我必须从我的网站向第三方域/服务器进行Web服务呼叫. 当我使用content-type:text/plain的jQuery Ajax by Post方法进行此调用时,它运行良好.
I have to make web service call from my websites to thirdparty domain/server. While I am making this call using jQuery Ajax by Post method with content-type:text/plain and it is working fine.
但是当我将其更改为content-type:text/xml时,它会抛出:
But while I am changing it to content-type: text/xml it is throwing:
对预检请求的响应未通过访问控制检查:否 请求中存在"Access-Control-Allow-Origin"标头 资源.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
即使在第三方服务器上进行了设置,也允许访问我们的网站.而且,在通过content-type:text/plain进行调用时,我们将获得此标头.
Even it set on thirdparty server to allow access to our website. And we are getting this header while making call with content-type:text/plain.
我们还在第三方服务器上添加了以下内容.
We have also added following on Thirdparty server.
Access-Control-Allow-Methods : Get , Post , Options ,PUT Access-Control-Allow-Headers: Authorization,origin, content-type, accept请让我知道飞行前请求未获得"Access-Control-Allow-Origin"作为响应的原因是什么?
Please let me know what could be the reason that pre-flight request is not getting 'Access-Control-Allow-Origin' in response?
推荐答案content-type:text/plain和content-type: text/xml之间的区别是:"text/xml"需要预检",而"text/plain"则不需要.
The difference between content-type:text/plain and content-type: text/xml is: "text/xml" requires "preflight" but "text/plain" does not.
来自 MDN :
尤其是在以下情况下,请求将被预检:
In particular, a request is preflighted if:
它使用GET,HEAD或POST以外的方法.另外,如果使用POST 发送具有Content-Type以外的Content-Type的请求数据 application/x-www-form-urlencoded,multipart/form-data或text/plain, 例如如果POST请求使用以下命令向服务器发送XML负载 application/xml或text/xml,则该请求被预检.
It uses methods other than GET, HEAD or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted.
一些可能导致预检请求失败的原因:
Some potential reasons those can cause the fail of a preflight request:
更多推荐
与Post一起使用交叉呼叫但在飞行前无法通过
发布评论