[英]How can I make cross-domain requests with custom headers without using XDomainRequest or XMLHttpRequest?
I have a single page web application delivered from www.example.com
. 我有一个从
www.example.com
发送的单页Web应用程序。 This web applications 这个Web应用程序
api.example.com
api.example.com
另一台服务器发出AJAX请求 Authorization
when sending requests to api.example.com
api.example.com
发送请求时设置某些标头字段,如Authorization
All this works by handling CORS requests on api.example.com with Chrome (and other recent WebKit-based browsers) using XMLHttpRequest
. 所有这一切都是通过使用
XMLHttpRequest
在Chrome(以及其他最近的基于WebKit的浏览器)上处理api.example.com上的CORS请求来实现的。 IE older than version 10 doesn't implement CORS for XMLHttpRequest
and instead provides the non-standard XDomainRequest
object for cross-domain requests. 早于版本10的IE不为
XMLHttpRequest
实现CORS,而是为跨域请求提供非标准XDomainRequest
对象。 But XDomainRequest
does not implement a way to set HTTP header fields. 但是
XDomainRequest
没有实现设置HTTP头字段的方法。
So my question is: How can I make cross-domain requests with custom headers without using XDomainRequest
or XMLHttpRequest
? 所以我的问题是:如何在不使用
XDomainRequest
或XMLHttpRequest
情况下使用自定义标头创建跨域请求? What is the best practice workaround? 什么是最佳实践解决方法?
Edit: I have control over all involved servers (*.example.com). 编辑:我可以控制所有涉及的服务器(* .example.com)。
I'm afraid there is no other way but to implement a proxy for this request in your application's server side. 我担心除了在应用程序服务器端为此请求实现代理之外别无他法。 An example .
一个例子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.