使用node.js从redirecturl获取响应头

目标:当我得到的状态代码为302redirecturi响应得到response.headers

问题:

我做了一些关于我在最后面对的问题的search,关于redirectURL返回500而不是预期的302.我发现npm request()可以用于redirect。 但是,我无法得到响应标题,因为它总是返回500.但是,当我用Postman(拦截器打开)与body和headers一起手动使用API​​端点时,我能够获得302redirect。 这主要用于API的自动化testing

request( url: 'https://blah/blah', client_id:'something.com.au' redirect_uri:'http://something' // used for mobile app and so it is OK to be have a valid url response_type :'code' scope : 'ALLAPI', Username : 'cxxx' Password : 'ccxcxc' headers : { 'Content-Type': 'application/x-www-form-urlencoded', 'followRedirect' : true }, function (error, response) { console.log('The response val is', response.statusCode); }); 

问题:不知道npm请求是否可以正确执行,或者我是否正确使用请求,或者是否需要使用axios / follow-redirects等等。 请指教。 如果任何人都可以提供正确的方向,这将是非常有益的

谢谢,布拉德

@所有。 我已经解决了使用表单属性,但使用req.post()方法返回状态码为302与响应头。 再次感谢所有。

我遇到了同样的问题, 针为我工作。

 var needle = require('needle'), url = 'https://www.ibm.com/common/ssi/cgi-bin/ssialias?htmlfid=GBE03831USEN&';; needle.get(url, {follow_max: 5}, function(error, res) { console.log(res.statusCode); });