Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Call API with custome header data #4

Closed
adminrai opened this issue Dec 29, 2020 · 10 comments
Closed

Unable to Call API with custome header data #4

adminrai opened this issue Dec 29, 2020 · 10 comments

Comments

@adminrai
Copy link

Hi
Please provide me help i am unable to call api from react with custome header data.

const response = fetch('http://localhost/server/logout',{headers: {'Auth': 'foobar'}});

Its through Error:
Access to fetch at 'http://localhost/server/logout' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

@afgprogrammer
Copy link
Owner

Try to call your route with Postman or any other API test service, if you still have this problem let me know.

@bradical1379
Copy link

bradical1379 commented Jan 1, 2021

I believe the issue is with the preflight OPTIONS method. I don't believe a service like Postman uses any preflight requests. I'd suggest adding something like this to the index.php file:

if ( 'OPTIONS' === $request->getMethod() ) {
    
    // fake set request url and method
    $router = new Router('/', "GET");
    
    $content = [
        "method" => $request->getMethod()
    ];
    
    $response->sendStatus(200);
    $response->setContent($content);
    
}

@adminrai
Copy link
Author

adminrai commented Jan 4, 2021

Thanks for your supports Its Working fine.
But now i face another problem.
On my localhost when i call api its runing fine.
But i upload this dir to server try to call API it show errro its show error.

Please help me.

@afgprogrammer
Copy link
Owner

@adminrai what error?

@adminrai
Copy link
Author

adminrai commented Jan 4, 2021

Is show 500 error

@afgprogrammer
Copy link
Owner

@adminrai The error doesn't have any content❓

@adminrai
Copy link
Author

adminrai commented Jan 4, 2021

This page isn’t working
relopsonline.com is currently unable to handle this request.
HTTP ERROR 500

@adminrai
Copy link
Author

adminrai commented Jan 4, 2021

When i dubug it in index.php
Before code
**use Router\Router;

// create object of request and response class
$request = new Http\Request();
$response = new Http\Response();**

is working but afrer this code its through error 500

@afgprogrammer
Copy link
Owner

@adminrai Your application hosted on this website 'relopsonline.com' or it's your endpoint?

@adminrai
Copy link
Author

adminrai commented Jan 4, 2021

Yes hosted on relopsonline.com and end point is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants