jQuery XML REST Access-Control-Allow-Origin

前端 未结 3 1617
孤独总比滥情好
孤独总比滥情好 2020-12-11 03:56

I am calling Version One REST API and keep getting XMLHttpRequest cannot load https://www10.v1host.com/... Origin http://localhost:8080 is not allowed by Access-Contro

3条回答
  •  一生所求
    2020-12-11 04:42

    It is not possible as long as the server of the REST API (not your server) allows the request from a different origin by setting the CORS (Cross-Origin Resource Sharing) HTTP header, for example by setting the "Access-Control-Allow-Origin" HTTP header in the response:

    Access-Control-Allow-Origin: *
    

    or

    Access-Control-Allow-Origin: http://localhost:8080
    

    However what you can do is call your own server with Ajax, then use your own server as a kind of proxy to make a call to the other server in a different domain, parse the XML or HTML result with a suitable parser, and give the result back to the client:

     client --(Ajax)--> server
                        server --(HTTP)---> Site 
                        server <----------
     client <----------
    

提交回复
热议问题