且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自定义请求标头未通过JavaScript获取请求发送

更新时间:2022-02-23 07:48:21

我终于解决了这个问题。浏览器请求实际上是我的服务器没有返回正确数据的CORS预检请求,这就是为什么fetch永远不会发送我的标题。

I finally resolved the issue. The browser request was actually the CORS preflight request in which my server was not returning the correct data so that is why fetch never sent my headers.

我现在使用这个Laravel包 https://github.com/barryvdh/laravel-cors 为PHP添加cors支持laravel app和al工作得很好!

I now use this Laravel package https://github.com/barryvdh/laravel-cors to add cors support to a PHP laravel app and al is working great!