jQuery, CORS, JSON (without padding) and authentication issues

前端 未结 3 696
滥情空心
滥情空心 2021-01-14 02:45

I have two domains. I\'m trying to access a JSON object from one domain through a page on another. I\'ve read everything I could find regarding this issue, and still can\'t

3条回答
  •  深忆病人
    2021-01-14 03:00

    Some examples available here may illustrate further how access control can be combined with CORS. Specifically the credentialed GET example. Access control requires that the request set the withCredentials flag to true on the XMLHttpRequest, and for the server handling the OPTIONS method to do two things:

    1. Set Access-Control-Allow-Credentials: true
    2. Not use a wildcard * in the Access-Control-Allow-Origin header. This has to be set to the origin exactly according to the MDN docs on HTTP access control (CORS).

    Essentially, the thing processing the OPTIONS request needs to send back appropriate response headers so you can make that credentialed request.

    In your question you stated that the service you are interacting with is returning Access-Control-Allow-Origin: *, which is not compatible with a credentialed cross-domain request. This needs to return the origin specifically.

    The aforementioned MDN Http Access Control (CORS) documentation also links to the Server-Side Access Control documentation outlining how a server would potentially respond to various cross domain requests - including handling a cross domain credentialed POST request that requires you to send back the correct headers in response to the OPTIONS method. You can find that example here.

提交回复
热议问题