Breeze-向请求添加标题 [英] Breeze - Adding headers to request

查看:89
本文介绍了Breeze-向请求添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与使用Breeze作为OData客户端的服务器集成,我使用常规jQuery post请求进行登录,并获取了需要添加到每个请求的令牌,如何将此令牌添加到breeze请求中?/p>

I am integrating with a server using Breeze as OData client, I made the login using regular jQuery post request and got back a token which I need to add to every request, how can I add this token to the breeze requests?

推荐答案

其要点如下.

当您选择OData数据服务时,Breeze将与服务器的通信(AJAX调用)委托给DataJS.这就是Breeze OData数据服务的实现方式.我们认为这是一个明智的选择,因为据我所知,Microsoft对维护DataJS负有主要责任.让Breeze更好地领导他们.

When you choose the OData dataservice, Breeze delegates communication with the server (the AJAX calls) to DataJS. That's how the Breeze OData dataservice is implemented. We think this is a wise choice because Microsoft (as I understand it) is substantially responsible for maintaining DataJS; better for Breeze to let them lead.

所以您应该寻找的是DataJS钩子.提出问题的同伴@bhlaban写道:

So what you should be looking for is DataJS hooks. The fellow who posed the question, @bhlaban, wrote this:

"我想我找到了一种解决方法:由于breeze在odata的后台使用了datajs,所以我只是从datajs论坛中执行了以下操作来设置授权标头:

var oldClient = OData.defaultHttpClient;

var myClient = {
     request: function (request, success, error) {
         request.headers.Authorization = $http.defaults.headers.common['Authorization'];
         return oldClient.request(request, success, error);
     }
};

OData.defaultHttpClient = myClient;

如果您不使用Angular的$http,则将以其他方式获取标头.

If you're not using Angular's $http, you'll get your header in some other way.

这篇关于Breeze-向请求添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆