Node.js请求库未设置所有cookie

Node.js请求库未设置所有cookie,node.js,http,cookies,Node.js,Http,Cookies,我在Node.js库中看到了这种奇怪的行为。服务器(bigbarket.com)发送的所有cookie都不在响应.headers或cookie jar中。不过,一切都适用于google.co.in var request = require('request'); // Start the first request request('http://bigbasket.com/', function (error, response, body) { if (!error &&

我在Node.js库中看到了这种奇怪的行为。服务器(
bigbarket.com
)发送的所有cookie都不在
响应.headers
或cookie jar中。不过,一切都适用于
google.co.in

var request = require('request');

// Start the first request
request('http://bigbasket.com/', function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(response.headers);
    }
});

// Start the second request
request('http://www.google.co.in/', function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(response.headers);
    }
});
上面的代码生成以下输出

>>============
>> http://www.google.co.in/
>>============
{ date: 'Tue, 21 Oct 2014 11:15:28 GMT',
  expires: '-1',
  'cache-control': 'private, max-age=0',
  'content-type': 'text/html; charset=ISO-8859-1',
  'set-cookie': 
   [ 'PREF=ID=5d1b92fe341ae90c:FF=0:TM=1413890128:LM=1413890128:S=McPDJGR9MFLDQ-E5; expires=Thu, 20-Oct-2016 11:15:28 GMT; path=/; domain=.google.co.in',
     'NID=67=wafc6_zujxhEsNgPfIAb5QGvbHW5GK8QpWfZMVIIvZQiuQHeYe-lM_nD_rlEIS2ZtTdSWA6wcgrfwaBXxySHJWiPJtqc6UBgHX3SYbk2ovxAq-TpyYTpsb79C90O3ht_; expires=Wed, 22-Apr-2015 11:15:28 GMT; path=/; domain=.google.co.in; HttpOnly' ],
  p3p: 'CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."',
  server: 'gws',
  'x-xss-protection': '1; mode=block',
  'x-frame-options': 'SAMEORIGIN',
  'alternate-protocol': '80:quic,p=0.01',
  'transfer-encoding': 'chunked' }
>>============
>>============
>> http://bigbasket.com/
>>============
{ 'content-type': 'text/html; charset=utf-8',
  date: 'Tue, 21 Oct 2014 11:15:27 GMT',
  server: 'nginx/1.4.6 (Ubuntu)',
  'set-cookie': [ 'csrftoken=808333d4e04b650a53e9e56433b10386; expires=Tue, 20-Oct-2015 11:15:27 GMT; Max-Age=31449600; Path=/' ],
  vary: 'Accept-Encoding',
  'transfer-encoding': 'chunked',
  connection: 'keep-alive' }
>>============
curl的输出显示,
7
cookies是由
bigbarket.com
服务器发送的,但上面的头转储中只存在
1
google.co.in
发送
2
,两者都出现在标题中

 ===============================================================================================================================
 bash $ curl -v http://www.google.co.in/ > /dev/null
 ===============================================================================================================================
* Hostname was NOT found in DNS cache
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 74.125.236.87...
* Connected to www.google.co.in (74.125.236.87) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: www.google.co.in
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Tue, 21 Oct 2014 10:07:22 GMT
< Expires: -1
< Cache-Control: private, max-age=0
< Content-Type: text/html; charset=ISO-8859-1
< Set-Cookie: PREF=ID=96fbe73447c47f15:FF=0:TM=1413886042:LM=1413886042:S=YtAcjeJChCMfvhoL; expires=Thu, 20-Oct-2016 10:07:22 GMT; path=/; domain=.google.co.in
< Set-Cookie: NID=67=hU3D52q3Heg7Fczrzc2xUEPVhQIsnYThGdstpZ1VGPmt80gYxTwX0dKjeQ13CL4vL2r_oJTA7U-si6Us70laG5Amgg1Ayv0ByAmz4ACkKRLK76qUajEbOw3h5IBwcObF; expires=Wed, 22-Apr-2015 10:07:22 GMT; path=/; domain=.google.co.in; HttpOnly
< P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
* Server gws is not blacklisted
< Server: gws
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Alternate-Protocol: 80:quic,p=0.01
< Transfer-Encoding: chunked
< 
{ [data not shown]
100 19019    0 19019    0     0  85796      0 --:--:-- --:--:-- --:--:-- 86058
* Connection #0 to host www.google.co.in left intact 
===============================================================================================================================

===============================================================================================================================
bash$ curl -v http://bigbasket.com/ > /dev/null
===============================================================================================================================
* Hostname was NOT found in DNS cache
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 122.248.250.187...
* Connected to bigbasket.com (122.248.250.187) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: bigbasket.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< Date: Tue, 21 Oct 2014 10:07:32 GMT
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Set-Cookie: _bb_ftvid="MzEzMTM2MzAwOA==|ZA0HTkMCAU4qBkRVUFJSBBBSV18AT1hRURB3LjE="; Domain=.bigbasket.com; expires=Tue, 21-Oct-2014 12:07:32 GMT; Max-Age=7200; Path=/
< Set-Cookie: _bb_vid="MzEzMTM2MzAwOA=="; Domain=.bigbasket.com; expires=Mon, 16-Oct-2034 10:07:32 GMT; Max-Age=630720000; Path=/
< Set-Cookie: sessionid=06531cfd4d53a6e6646d09fe055b571a; Domain=.bigbasket.com; expires=Tue, 04-Nov-2014 10:07:32 GMT; Max-Age=1209600; Path=/
< Set-Cookie: _bb_tc=0; Domain=.bigbasket.com; expires=Wed, 21-Oct-2015 10:07:31 GMT; Max-Age=31536000; Path=/
< Set-Cookie: csrftoken=37adbe93f43608cb6fbfb609d8ad34a4; expires=Tue, 20-Oct-2015 10:07:32 GMT; Max-Age=31449600; Path=/
< Set-Cookie: _bb_rdt="MzE1MDAyNDY0Mw==.0"; Domain=.bigbasket.com; expires=Wed, 21-Oct-2015 10:07:31 GMT; Max-Age=31536000; Path=/
< Set-Cookie: _bb_rd=2; Domain=.bigbasket.com; expires=Wed, 21-Oct-2015 10:07:31 GMT; Max-Age=31536000; Path=/
< Vary: Accept-Encoding
< Vary: Cookie, Accept-Encoding
< transfer-encoding: chunked
< Connection: keep-alive
< 
{ [data not shown]
100  115k    0  115k    0     0  96407      0 --:--:--  0:00:01 --:--:-- 96449
* Connection #0 to host bigbasket.com left intact
===============================================================================================================================
===============================================================================================================================
bash$curl-vhttp://www.google.co.in/ >/dev/null
===============================================================================================================================
*在DNS缓存中找不到主机名
%总接收百分比%x平均速度时间电流
数据加载上载总左速度
0 0 0 0 0 0 0--:-:-:-:-:---:-:---0*正在尝试74.125.236.87。。。
*已连接到www.google.co.in(74.125.236.87)端口80(#0)
>GET/HTTP/1.1
>用户代理:curl/7.38.0
>主持人:www.google.co.in
>接受:*/*
> 
/dev/null
===============================================================================================================================
*在DNS缓存中找不到主机名
%总接收百分比%x平均速度时间电流
数据加载上载总左速度
0 0 0 0 0 0 0--:-:-:-:-:-:---:---0*正在尝试122.248.250.187。。。
*连接到bigbarket.com(122.248.250.187)端口80(#0)
>GET/HTTP/1.1
>用户代理:curl/7.38.0
>主持人:bigbarket.com
>接受:*/*
> 

工作代码在

问题是该网站正在期待/嗅探
用户代理
,而
请求
默认情况下不发送

这将在响应中显示各种
Set Cookie
标题:

request('http://bigbasket.com/', {
  headers: {
    'User-Agent': 'node.js'
  }
}, function (error, response, body) {
  console.dir(response.headers);
});
就是这样。:-)谢谢。这种行为有记录吗?