关于这个问题: Transfer / pass cookies from one request to another in nodejs/protractor
我又来了一个。我怎样才能查看我通过nodejs执行的完整请求(标题+正文)?
答案 0 :(得分:1)
是的,您可以......您可以访问完整回复正文的完整请求 - response.request
我有一个通用的完整响应结构,如下所示
IncomingMessage
ReadableState
headers(ResponseHeaders)
rawHeaders
request - //This is what you need
headers
body
body(Response Body)
您可以通过以下代码访问
var request = require("request");
var options = { method: 'POST',
url: 'http://1.1.1.1/login',
headers:
{ 'cache-control': 'no-cache',
'content-type': 'application/json' },
body: { email: 'junk@junk.com', password: 'junk@123' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
// This will give you complete request
console.log(response.request);
//This gives you the headers from Request
console.log(response.request.headers);
});