简体   繁体   English

nodejs请求从服务器返回null body以获取POST请求

[英]nodejs request returning null body from server for a POST request

I am sending an http post request from node using request ( https://github.com/mikeal/request ), and I am getting back a null body. 我正在使用请求( https://github.com/mikeal/request )从节点发送http post请求,并且我正在返回一个空主体。 The same request getting sent from hurl.it is returning the correct response with the correct body. 从hurl.it发送的相同请求正在返回正确的正文响应。 Another request getting sent from the same nodejs server to the same server is also returning the correct body. 从同一nodejs服务器发送到同一服务器的另一个请求也返回正确的主体。 What is really infuriating is that this was working last week and is no longer working in nodejs. 真正令人气愤的是,这是在上周工作,不再在nodejs工作。

My server.js is: 我的server.js是:

var request = require('request');

request({
        uri: 'insert url here; contains sensitive info',
        method: 'POST',
        body: 'insert body here; contains sensitive info',
        followRedirect: true,
        maxRedirects: 10
        }, function(error, response, body) {
                console.log('body in response is: ' + body);
        });

anyone have any idea how to fix this? 有谁知道如何解决这个问题?

thank you. 谢谢。

I resolved this issue. 我解决了这个问题。 The server I was posting to was apparently expecting a User Agent in the header that I wasn't sending, was throwing a null exception, and returning null. 我发布的服务器显然是期望我没有发送的标头中的用户代理,抛出空异常,并返回null。 It has since been fixed. 它已被修复。

Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM