Breeze - Adding headers to request

╄→尐↘猪︶ㄣ 提交于 2019-12-02 21:56:26

问题


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?


回答1:


A similar question appeared in the comments to Brian Noyes (wonderful) Pluralsight course on Breeze.

The gist of it as follows.

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.

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

"I think I found a work around: Since breeze uses datajs under the hood for odata, I just did the following (from datajs forum) to set the authorization header:

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;

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



来源:https://stackoverflow.com/questions/20458916/breeze-adding-headers-to-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!