【发布时间】:2017-01-25 19:55:00
【问题描述】:
我在本地运行一个 Flask-Restful API,并从不同的端口发送一个包含 JSON 的 POST 请求。我收到了错误
No 'Access-Control-Allow-Origin' header is present on the requested resource.
但是,当我跑步时
curl --include -X OPTIONS http://localhost:5000/api/comments/3
--header Access-Control-Request-Method:POST
--header Access-Control-Request-Headers:Content-Type
--header Origin:http://localhost:8080
我明白了
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Allow: HEAD, GET, POST, OPTIONS
Access-Control-Allow-Origin: http://localhost:8080
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
Vary: Origin
Access-Control-Allow-Headers: Content-Type
Content-Length: 0
将“Access-Control-Allow-Origin”显示为“*”。 GET 工作正常,只是 POST 给出了这个错误。可能出了什么问题?如果相关,对于我正在使用的前端 react 和通过 axios 请求。
【问题讨论】:
-
您好,您找到解决方案了吗?我也遇到了同样的情况,任何更新都会有所帮助。
标签: python flask cors axios flask-cors