0

我正在调用我的客户提供的 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 post时:

        var response = $.post(loginUrl, parameters, authenticateSuccess);

        function authenticateSuccess(html, textStatus, data) {
          alert("in authenticateSuccess()");
          console.log("headers: " + data.getAllResponseHeaders());
        }

打印以下日志信息(注意单个 set-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

先感谢您。

4

1 回答 1

0

当前标准化 XMLHttpRequest API 的状态仅限制对 Set-Cookie 和 Set-Cookie2 标头字段的访问:

client.getAllResponseHeaders()

返回响应中的所有标头,但字段名称为 Set-Cookie 或 Set-Cookie2 的标头除外。

于 2014-01-06T01:39:58.050 回答