How do I set headers before letting breeze make a request?
Example: my service expects a certain key to be part of the request in
a header name ‘x-service-key’. Till Now,I was using jquery ajax and
amplify,so pretty easy to set up the header. Since I don’t have any
control over the request that breeze is making,how do I pass extra
stuff like headers?
这个问题是由sujesharukil在我们的IdeaBlade论坛上发布的.我在这里重新提出问题和答案,因为我认为它对Breeze Stack Overflow社区有用.
解决方法
从Breeze 0.70.1开始,我们现在支持完全自定义或替换breeze客户端与服务器上的Web服务之间的任何Ajax通信的能力.
关于我们的Ajax支持的Breeze文档仍在进行中,但希望以下内容可以帮助您入门.
要控制Breeze发出的每个Ajax请求的标头,您可以在应用首次启动时执行以下代码.
var ajaxImpl = breeze.config.getAdapterInstance("ajax"); ajaxImpl.defaultSettings = { headers: { // any CORS or other headers that you want to specify. "X-Test-Header": "foo2" },};
或者,您可以拦截单个Ajax调用,并根据请求有选择地添加标头.
var ajaxImpl = breeze.config.getAdapterInstance("ajax"); ajaxImpl.defaultSettings = { beforeSend: function(jqXHR,settings) { // examine the jqXHR or settings and customize the headers accordingly. jqXHR.setRequestHeader("X-Test-Before-Send-Header","foo2"); } };
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。