我遇到了与this post类似的问题,但最好的答案并没有帮助我。如果有人有任何其他想法,我将不胜感激。以下是要求:
请求标题
OPTIONS
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type,x-annotator-auth-token,x-csrftoken
响应标题
Access-Control-Max-Age: 3600
Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
Access-Control-Allow-Headers: content-length, content-type, x-annotator-auth-token, x-requested-with, x-csrftoken
Access-Control-Allow-Credentials: true
它返回状态代码为200.实际请求包含content-length,content-type,x-annotator-auth-token和x-csrftoken,但没有获得状态代码,就像它从未触发一样。再次任何帮助将不胜感激!感谢
答案 0 :(得分:3)
response.addHeader("Access-Control-Allow-Origin", "*");
或
response.addHeader("Access-Control-Allow-Credentials","true");
和
response.addHeader("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS");
response.addHeader("Access-Control-Allow-Headers", "Content-Type, X-Experience-API-Version,Authorization");
//add this into your response header and it will work