我正在调用客户端提供的RESTful Web服务。使用CocoaRestClient(我在Mac上),我可以看到返回多个Set-Cookie标头。但是,当我尝试在我的应用程序的响应标头中检索这些cookie时(使用PhoneGap),标题中只返回最后一个set-cookie值。
CocoaRestClient显示返回的以下cookie:
Set-Cookie: SMSESSION=YTpvYLPQOYNoZjqHb1fvOc37lrmYmj0yk2NO2meBWkd2Bf3SE+rNd2aiEI+vGNNkis82PZMuQklvQg8O0lFL0Qq0Wg13g7baJ784gqjPXXjNn5Mc6YxjWNIULxCy8cMP0/y7S4fYxLbr7CFv0g4Z9y+PaKMyCRGCydT7MwTIFUJZ7zRCr+hVo0HzA/uH+xi0fVNWVrN3mltnRSeBgePtBxBeh4hEIT725ufHsiq04HaaR4A9e+NKPdAOj8lZJf76Su+q/bwUU0qmlcnouDU4i5p4WGRC78w8tmBhmwH640UmPipXZSJBoccXmsB5hg4wr8fMMA5H1Z2mP35cYHNeAj12GaiYnlRpfEaRyTxroDYO0zJeYDIve6QV4aZu74erN1r0jsU7JPK408CYPhFG5VGtBRwd2Xq6iJDjVGMB7uIrxtnomtiUyX+AOHhMvj7b982D4PZrZkTACSWU+kfBhIb1/3ryLBuG4db3ICNDJtKuSlsykTI4g+wtRf3rOnylrmtstK7hyfGED/LpD7hqMDO51hZCkoobFHxUuxkxhj2Gh7KtH9DFFhpdbqPBzfadMFZC8kaVJlDkB8Ex5jRyqj7fpdmyVSUIO9FC+sG7Jew81EW1ZSJyjMopUrxirk0YNVuke9KePZxJdP8IRWa4hLGt2hAQDbe5gn3vRSMQgEZsRpCtSSF2gpUe1wuih7jR/UPutNjRzwm7AgTU3bI7Peg+glSMCf2zMeXtt7S+fLf6TIZtV3wJg8O3o2VzLtDvCuJwxArlO8tSW0FodIwD6pQTG9TiWiXs2vi7eHPq++Toh21lMONg1dS9jJbaPkdiIficA9jX6Jx8LrIWKAaHT+c4N43TuZ5AsLRD7dX/xar/ekglGHu0eh5jQF917KyLsa1rZJyJjS9zW8nSmm5dppbBdYIuSyOnEjVrPCinXmxXSMZ/3iaZvoRKBXajwsry0lHI5ZCehotKIP6z7I/u8iXrp6tcqk2xi+X7dyHJnzAIdvwcLv37RqVCcH/WUosb6/Swr2fpPfuqu+qiqCbbYbCZh+f7JDb0b/ONhMs/g5dWPqSDBV51+a6XXd5ZQM69f0vmCPMQxE/aDhRX26IRdqCngkrjSQl6YyfPsLs6+aXtcyWoQuirzvYFJwlI4PKxFv3QAiO8hwCHL9wSWv4cTk/fHKKXvqToL4fvwTJB4WFIkK9Tyv1NU2g//djPaX8jUlrdbchLDuYRfhfYhyKNBhOD6gb/tH30; path=/; domain=.abc.com; secure, ActiveResponse=""; path=/; domain=.abc.com; secure, SMIDENTITY=""; path=/; domain=.abc.com; secure, blueboxvalues=""; path=/; domain=.abc.com; secure, BHAROSA_TARGET5=""; path=/; domain=.abc.com; secure, BHAROSA_TARGET=""; path=/; domain=.abc.com; secure, sm_universalid=e0494209bb9a934c29e70fe09a1cc67Z; path=/; domain=.abc.com; secure, BHAROSA_APP_NAME=""; path=/; domain=.abc.com; secure, subscribed_services=SSOService^175; path=/; domain=.abc.com; secure, bharosaenrolled=""; path=/; domain=.abc.com; secure, AUTHRESPONSE=""; path=/; domain=.abc.com; secure
当像这样使用jquery帖子时:
var response = $.post(loginUrl, parameters, authenticateSuccess);
function authenticateSuccess(html, textStatus, data) {
alert("in authenticateSuccess()");
console.log("headers: " + data.getAllResponseHeaders());
}
打印以下日志信息(请注意单一设置Cookie行):
headers: date: Mon, 03 Jun 2013 14:27:28 GMT
content-encoding: gzip
x-mod-pagespeed: 1.0.22.7-2005
content-length: 9372
pragma: no-cache
server: Apache
vary: Accept-Encoding
content-type: text/html
cache-control: max-age=0, no-store, no-cache, must-revalidate
set-cookie: AUTHRESPONSE=""; path=/; domain=.abc.com; secure
accept-ranges: bytes
我也尝试过使用ajax post和XMLHttpRequest。所有人都做同样的事情。
那么为什么只在标题中检索到最后一个Set-cookie标头?
同样的问题显然是问过但从未在这里回答:How to get two cookies back from jquery getResponseHeader('Set-Cookie') for Android
提前谢谢。
答案 0 :(得分:0)
标准化XMLHttpRequest API的当前状态仅限制对Set-Cookie和Set-Cookie2标头字段的访问:
client.getAllResponseHeaders()
返回响应中的所有标头,但字段名称为Set-Cookie或Set-Cookie2的标头除外。