Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 405 error - method not allow error in swagger while working in postman

I 'm tring to run my API in swagger editor. But if I pass oauth token in header it gives me an error that 405 method is not allowed.

One more thing is it's working perfect in postman and terminal with oauth token. So maybe, the issue is with swagger.

Without oauth token it's working perfect in swagger editor.

Without Passing oauth token in header my response is

Request URL:http://172.168.1.28/crowdfunding_api/public/v1.0.1/categories
Request Method:GET
Status Code:200 OK
Remote Address:172.168.1.28:80
Referrer Policy:no-referrer-when-downgrade

and curl url is when response is 200:

curl -X GET "http://172.168.1.28/crowdfunding_api/public/v1.0.1/categories" -H "accept: application/json"

With oauth token in header my response is

Request URL:http://172.168.1.28/crowdfunding_api/public/v1.0.1/categories
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Remote Address:172.168.1.28:80
Referrer Policy:no-referrer-when-downgrade

and curl url is when response is 405:

curl -X GET "http://172.168.1.28/crowdfunding_api/public/v1.0.1/categories" -H "accept: application/json" -H "authorization: 587ded3104e6ba7535642e6fcc217e7aa0f5f087"
like image 776
Dhaval Avatar asked Nov 23 '25 15:11

Dhaval


1 Answers

Try to add support for OPTIONS method in your REST endpoint wrapper. Just use something like:

if (method == 'OPTIONS') return;

I had similar 405 error and this helped me (seems that CORS sends OPTIONS first to check headers, whether request is allowed).

Also make sure, that your server returns headers:

Access-Control-Allow-Credentials: "true"
Access-Control-Allow-Origin: "*"
Access-Control-Allow-Headers: "origin, x-requested-with, content-type, authorization"
Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
like image 162
megastruktur Avatar answered Nov 25 '25 10:11

megastruktur