dongzhang0243 2018-10-03 06:33
浏览 694
已采纳

预检响应不允许的CORS Error 405方法没有HTTP ok状态

I've been trying using axios from Vue calling to my API in lumen but it sends options method in place of post because of CORS.

Here is my request details

General

Request URL: http://192.168.1.100/lv_api/code/login

Request Method: OPTIONS

Status Code: 405 Method Not Allowed

Remote Address: 192.168.1.100:80

Referrer Policy: no-referrer-when-downgrade

Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token, X-
Requested-With

Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS

Access-Control-Allow-Origin: http://192.168.1.100:8000

Allow: POST

Cache-Control: no-cache, private

Connection: close

Content-Type: text/html; charset=UTF-8

Date: Wed, 03 Oct 2018 06:22:56 GMT

Server: Apache/2.4.18 (Ubuntu)

Accept: */*

Accept-Encoding: gzip, deflate

Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

Access-Control-Request-Headers: content-type

Access-Control-Request-Method: POST

Connection: keep-alive

Host: 192.168.1.100

Origin: http://192.168.1.100:8000

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

Tried setting headers but I am not sure about the proper values to be set for the issue.

If I create a method for Options request in my API it works fine but that's not the proper solution to this.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • douya1855 2018-10-03 09:26
    关注

    Resolved the issue just by adding following lines in my api code

    header('Access-Control-Allow-Origin: your origin');
    header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age:86400');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token,  Accept, Authorization, X-Requested-With');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?