带有自定义标头的JayData oData请求 [英] JayData oData request with custom headers

查看:148
本文介绍了带有自定义标头的JayData oData请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将自定义标头发送到我的wcf oData服务,但是使用以下功能,标头不会被修改。

I need to send custom headers to my wcf oData Service but with the following function the headers dont get modified.

entities.onReady(function () {

    entities.prepareRequest = function(r) {
        r[0].headers['APIKey'] = 'ABC';
    };

    entities.DataServiceClient.toArray(function (cli) {
        cli.forEach(function (c) {
            console.log(c.Name)
        });
    });
});

标题不受影响。任何线索?

headers are not affected. any clue?

谢谢!

推荐答案

编辑



第二个想法,似乎JayData中的MERGE请求仍然存在问题。

EDIT

On second thought, it seems like there is still something broken in JayData for MERGE requests.

这不是CORS并且有与它无关!

This is NOT CORS and has nothing to do with it!

参见具有自定义标题的JayData oData请求 - ROUND 2

波纹管hack有效,但上述问题应该将此问题解决一个新的水平。

the bellow "hack" works, but the above question should take this problem to a new level.

没关系我找到了解决方案。

Nevermind I found a solution.

似乎 prepareRequest 是在JayData 1.3.2(ODataProvider)中断开。

It seems like prepareRequest is broken in JayData 1.3.2 (ODataProvider).

作为一个hack,我在providerConfiguration(oDataProvider.js)中添加了一个extraHeaders对象:

As a hack, I added an extraHeaders object in the providerConfiguration (oDataProvider.js):

  this.providerConfiguration = $data.typeSystem.extend({
                   //Leave content unchanged and add the following:
                    extraHeaders: {}
                }, cfg);

然后在第865行修改requestData这样:

then at line 865 modify requestData like this:

var requestData = [
                    {
                        requestUri: this.providerConfiguration.oDataServiceHost + sql.queryText,
                        method: sql.method,
                        data: sql.postData,
                        headers: _.extend({
                            MaxDataServiceVersion: this.providerConfiguration.maxDataServiceVersion
                        },this.providerConfiguration.extraHeaders)
                    },

注意:Iam使用lodash进行召集,任何js扩展应该可以解决问题。

NOTE: Iam using lodash for conveniance, any js extend should do the trick.

然后你就像这样创建你的客户:

then you just create your client like this:

 var entities = new Entities.MyEntities({
            name: 'oData',
            oDataServiceHost: 'http://myhost.com/DataService.svc',
            maxDataServiceVersion: "2.0",
            //enableJSONP: true,
            extraHeaders: {apikey:'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5', Accept:'application/json;odata=verbose'}
        }
    );

这篇关于带有自定义标头的JayData oData请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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