如何在使用jsonp代理时发送标头? [英] How to send headers while using jsonp proxy?

查看:194
本文介绍了如何在使用jsonp代理时发送标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的应用程序中获取Web服务的数据以加载列表并使用pull refresh& ListPaging插件。我用flickr API尝试了这个并且它工作正常,但是当我尝试访问我们自己的服务时出现问题,因为他们期望使用Base64编码数据的Authorization头和Accept头来决定响应的格式。

I am trying to get data from web services from my app to load a list and to load more on scroll using pull refresh & ListPaging plugins. I tried this with flickr API and it works fine, but problem comes when I try to access our own services because they expect "Authorization" header with Base64 encoded data and "Accept" header to decide format of response.

这就是我定义商店的方式:

This is how I have defined my store:

Ext.define('myshop.store.CatalogListStore',{
    extend:'Ext.data.Store',
    requires: [
        'myshop.model.CatalogListItem'
    ],
    config:{
        model:'myshop.model.CatalogListItem',
        autoLoad :true,
        proxy: {
            type: 'jsonp',
            url: 'http://192.168.23.89:7003/xxx-service/test/catalog/list',
            useDefaultXhrHeader : false,
            withCredentials:true,
            method : 'GET',
            headers: {
                'Accept': 'application/json',
                'Authorization': 'Basic YX5iOmM='
            },
            extraParams: {
                format : 'json',
                pagesize : 10
            },
            reader: {
                type: 'json',
                rootProperty: 'categories.data'
            }
        }
    }
}

这是我在Chrome的网络控制台中看到的:

This is what I see in Chrome's network console:

Request URL:http://192.168.23.89:7003/xxx-service/test/catalog/list?_dc=1354529083930&format=json&pagesize=10&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback2
Request Method:GET
Status Code:403 Forbidden
**Request Headers**
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:192.168.23.89:7003
Referer:http://localhost/myshop/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11
**Query String Parameters**
_dc:1354529083930
format:json
pagesize:10
page:1
start:0
limit:25
callback:Ext.data.JsonP.callback2
Response Headersview source
Content-Length:0
Content-Type:text/xml
Date:Mon, 03 Dec 2012 10:04:40 GMT
Server:Apache-Coyote/1.1

如果我使用Poster通过Authorization标头访问这些服务,我可以看到响应,但由于Headers不是在请求中传递我获得403禁止状态。

If I use Poster to access these services with Authorization header I am able to see response but since Headers are not passed in request I am getting "403 forbidden" status.

如果我使用这样的标题它可以工作:

If I use headers like this it works :

Ext.Ajax.request({
        url: 'resources/data/templates.json',
        headers: {
            'Accept': 'application/json',
            'Authorization': 'Basic T3JkZXJSZWxlYXNlUmVmcmVzaGVyfk9yZGVyUmVsZWFzZVJlZnJlc2hlcjpPcmRlclJlbGVhc2VSZWZyZXNoZXI='
        },
        success: function(rsp){
        }
});

但是我不能这样做,因为我想使用listPaging插件。

but I cannot do this because I want to use listPaging plugin.

推荐答案

JSONP Works购买将请求URL插入页眉中,如果您需要验证您的请求,则必须将其放入URL中,例如:

JSONP Works buy inserting the request URL as a in the the page header, if you need to authenticate your request, you will have to put it in the URL eg:

'http://192.168.23.89:7003/xxx-service/test/catalog/list?auth=1223456'

您确定需要使用JSONP吗?

Are you certain you need to use JSONP?

有关详细信息,请参阅此答案

See this answer for more info

这篇关于如何在使用jsonp代理时发送标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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