如何查看从node.js发送到服务器的请求? [英] How to view request sent from node.js to server?

查看:447
本文介绍了如何查看从node.js发送到服务器的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于此问题:
在nodejs / protractor中将cookie从一个请求传输/传递到另一个请求

我得到了另一个请求。

I got another one. How could I view complete request (headers + body) which I am performing via nodejs?

推荐答案

是的,我可以如何查看通过nodejs执行的完整请求(标头+正文)?您可以从完整响应正文访问完整请求- response.request

Yes, you can ... You can access the complete request from the full response body - response.request

我有一个通用的完整响应结构如下所示

I have a generic full response structure illustrated below

IncomingMessage
  ReadableState
  headers(ResponseHeaders)
  rawHeaders
  request - //This is what you need
    headers 
    body
  body(Response Body)

您可以通过如下所示的代码访问

You can access through code as shown below

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);
});

这篇关于如何查看从node.js发送到服务器的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆