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

预检响应不允许的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条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘