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条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配