ajax请求修改标题,jQuery AJAX自定义标题

我正在尝试对iContact API执行一个请求,这需要我使用自定义标头进行身份验证(http://developer.icontact.com/documentation/authenticate-requests).这是我的代码:

$.ajax({

type: "GET",url: "https://app.icontact.com/icp/a/",contentType: "application/json",beforeSend: function(jqXHR,settings){

jqXHR.setRequestHeader("Accept","application/json");

jqXHR.setRequestHeader("Api-Version",iContact_API_version);

jqXHR.setRequestHeader("Api-AppId",iContact_appID);

jqXHR.setRequestHeader("Api-Username",iContact_username);

jqXHR.setRequestHeader("API-Password",iContact_appPassword);}

});

由于某种原因,请求不会通过.但是,当我手动执行相同的请求(使用Chrome REST控制台)时,它的工作正常.如果我取出了自定义标头(API- *),请求就会通过,但是当然,认证失败,我收到一个常规的HTML页面.

我切换到Firefox并检查了请求/响应头:

请求:

Host app.icontact.com

User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12

Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language en-us,en;q=0.5

Accept-Encoding gzip,deflate

Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive 115

Connection keep-alive

Origin http://184.72.61.244

Access-Control-Request-Me... GET

Access-Control-Request-He... api-appid,api-password,api-username,api-version

响应:

HTTP/1.1 302 Found

Date: Tue,14 Jun 2011 23:43:56 GMT

Server: Apache/2.2.9 (Debian)

Set-Cookie: intellicontact_PHPsess=1c7ca333017b47f46edd893dae584781; path=/; domain=.icontact.com; secure; HttpOnly

Expires: Thu,19 Nov 1981 08:52:00 GMT

Cache-Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0

Pragma: no-cache

Location: https://app.icontact.com/icp/login/sentry.PHP?relurl=https%3A%2F%2Fapp.icontact.com%2Ficp%2Fa%2F&sess=

Vary: Accept-Encoding

Content-Encoding: gzip

Content-Length: 20

Connection: close

Content-Type: text/html; charset=utf-8

任何想法在这里出了什么问题?

谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值