简体   繁体   中英

How can i bypass CORS Policy with ASP.NET and Ajax?

I want to bypass CORS Policy to GET data XML from another domain. I try so much but have no luck. There are:

  • JSONP : By this way, i don't know how to use it. Because XML Construction is difference from JSONP Construction. If yes, please help me how to use JSONP to get data XML from another domain.
  • Proxy : Cause of my project is ASP.NET Framework 4.0. So, i create a proxy page and use it to get XML. Example: http://localhost:4030/proxy.aspx?u=http://onotherdomain.com/data.xml . But i can't get data with a basic protected site. It's allways return 401 unauthorized.

For you, JSONP is faster or Proxy is Faster ?

Thanks for watching ?

If the other domain does not explicitly trust you, you cannot invoke it from the client via AJAX for security reasons unless you use JSONP.

However, you can only use JSONP as long as you are sticking to only GET requests and the server knows how to respond with a JSONP-formatted response.

On the other hand, if they DO explicitly trust you, you have a few options.

  • CORS support on the server as long as you are using modern browsers (IE9 still has issues with this) with the appropriate headers.
  • XDomain , which is essentially a javascript proxy shim. However, this also requires explicit request domain inclusion.

On the other hand, if you create a proxy server-side on your end that can call across to the other domain, you'll have no issues whatsoever.

A server-side proxy should in theory always be slower than ajax options since you are making two calls instead of one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM