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

伊尔沙德

我在Node.js请求库中看到了这种奇怪的行为服务器(bigbasket.com发送的所有cookie都不存在于response.headerscookie罐中或cookie罐中。一切正常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的输出显示7cookie是由bigbasket.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
===============================================================================================================================

Runnable的工作代码

mscdex

问题在于该网站正在等待/嗅探User-Agentrequest并且默认情况下不会发送任何内容。

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

request('http://bigbasket.com/', {
  headers: {
    'User-Agent': 'node.js'
  }
}, function (error, response, body) {
  console.dir(response.headers);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在 node.js 中打印所有 cookie?

来自分类Dev

所有请求的Node.js静态标头

来自分类Dev

cookie未在node.js中设置

来自分类Dev

Node.js-未设置某些标头

来自分类Dev

标头未设置 node.js api 推送通知

来自分类Dev

布尔值未设置为 true node.js

来自分类Dev

Node.js请求库的相对uri

来自分类Dev

带有后端node.js服务器的create-react-app与未设置node.js服务器的create-react-app之间的区别

来自分类Dev

Node JS 请求 - 如何使响应正文可用于所有其他 JS

来自分类Dev

Node.js:通过专有传输协议使用现有库的HTTP / REST请求

来自分类Dev

没有Node.js的Node.js库

来自分类Dev

NODE JS取消请求

来自分类Dev

如何从node.js中的请求模块获取cookie?

来自分类Dev

使用AXIOS(Node.js)在请求之间保留cookie

来自分类Dev

如何使用请求方法 Node.JS 处理 cookie

来自分类Dev

未设置NODE_DEBUG变量

来自分类Dev

未设置NODE_DEBUG变量

来自分类Dev

在node.js中所有传入的HTTP请求上提供index.html

来自分类Dev

在过滤node.js中的所有发布请求之前

来自分类Dev

如何允许 Node.js 服务器接受 Ubuntu 上的所有请求?

来自分类Dev

带有node.js的http请求失败,发送后无法设置标头

来自分类Dev

Node JS Async Promise。所有问题

来自分类Dev

Node.js-writeHead设置“位置”和“ Set-Cookie”

来自分类Dev

使用Node.js设置HTTP标头Cookie

来自分类Dev

将Python请求库转换为Node.js

来自分类Dev

在Node.js请求模块上设置{“ agent”:false}

来自分类Dev

在Node.js中设置请求标头

来自分类Dev

如何在请求中使用cookie(request,tough-cookie,node.js)

来自分类Dev

如何在请求中使用cookie(request,tough-cookie,node.js)

Related 相关文章

热门标签

归档