weixin_33727510 2016-08-02 17:14 采纳率: 0%
浏览 116

Nginx Web浏览器的CORS问题

I'm working on an AngularJS Application which uses an external API and I got a weird issue (CORS). I made a lot of research that does not fix the issue.

When I hit my API the preflight request is good (status 204 No-Content), but when the server responds with a another status code than 2xx (200, 204 etc...) I got the CORS issue.

If my server send back 2xx as status code is alright we have no CORS issue but if another status code is sent here is the problem.

API : Sylex(PHP Framework) running under Nginx

Front application : AngularJS - using webpack

XHR VIEW :

XHR view

Console CORS Error :

Console CORS Error

  • 写回答

1条回答 默认 最新

  • helloxielan 2016-08-09 20:35
    关注

    After a day of search I figured out where the CORS was coming from. The Nginx configuration was ok. It was the API.

    During the preflight request (OPTIONS) the server let passed the request because NGINX allowed the origin and header (access-control-allow-origin, access-control-allow-headers),

    but when the API sends back the response the headers were not set up.

    I fixed it by adding the access-control-allow-origin and access-control-allow-headers to the response.

    IMPORTANT: I figured out data weren't recoverable in the response with the 200 status code on the webbrowser. To fix it remove the headers added in the others responses (5xx, 4xx, etc..) (I don't know if its just in my case)

    I haven't developed the API that's why it takes me a day to figure it out. Hope I will help someone with this use case :)

    评论

报告相同问题?

悬赏问题

  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。