[英]Can't get set-cookie from header in response with NodeJS
我在節點中嘗試了3種不同的http庫
這3個庫都無法從我的回復中獲取我的set-cookie
請求
15:32:52 - WARN - now testing with request
{ 'x-powered-by': 'Express',
'content-type': 'application/json; charset=utf-8',
'content-length': '4591',
date: 'Thu, 11 Dec 2014 14:32:52 GMT',
connection: 'keep-alive' }
針
15:32:52 - WARN - now testing with needle
{ 'x-powered-by': 'Express',
'content-type': 'application/json; charset=utf-8',
'content-length': '4591',
date: 'Thu, 11 Dec 2014 14:32:52 GMT',
connection: 'close' }
請求
15:32:52 - WARN - now testing with requestify
{ 'x-powered-by': 'Express',
'content-type': 'application/json; charset=utf-8',
'content-length': '4591',
date: 'Thu, 11 Dec 2014 14:32:52 GMT',
connection: 'keep-alive' }
這是帶有wget的結果標頭
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Date: Thu, 11 Dec 2014 14:38:49 GMT
Cache-Control: public, max-age=0
Last-Modified: Thu, 11 Dec 2014 09:56:58 GMT
ETag: W/"7c2-2140188116"
Content-Type: text/html; charset=UTF-8
Content-Length: 1986
set-cookie: session=s%3AHI2alIkPOxVLXgJCymvAPbTZt1urIpEE.dBB7ZrpWjKAkwSALBVgbyJtRq9ZABMq9VJh%2F3XT6r8A; Path=/; Expires=Thu, 11 Dec 2014 15:08:49 GMT; HttpOnly
Connection: keep-alive
Length: 1986 (1.9K) [text/html]
如果這可以幫助,這是我請求中的標題
var commonHeaders = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'fr',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'User-Agent': 'request'
};
雖然firefox,chrome和wget可以獲取完整的標頭,但我無法使用node進行身份驗證。 Node有問題嗎? 我應該在Python中這樣做嗎?
編輯:
我試圖刪除通過節點發布的數據,我的響應也與使用wget的響應相同。 當我使用瀏覽器並執行登錄操作時,它將返回我的json + set-cookie。
為什么用node不可能呢?
您可能沒有正確使用Cookie。 通常,它們不作為標頭變量直接訪問。 有關如何處理Cookie的信息,請參閱請求文檔。那里有很好的示例。
Cookies默認是禁用的(否則,它們將在后續請求中使用)。 要啟用cookie,請將jar設置為true(默認設置或選項),然后安裝hard-cookie。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.