使用node.js从重定向URL获取响应头

时间:2016-02-29 04:14:39

标签: node.js

目的:  当我从重定向uri响应

获取状态代码为302时,获取response.headers

问题:

我做了一些关于一个问题的谷歌搜索,我面临的问题是重定向URL返回500而不是预期的302.我发现npm request()可以用于重定向。但是我无法获得响应标头,因为它总是返回500.但是当我使用Postman手动使用API​​端点(拦截器打开)以及主体和标头时,我能够获得302重定向。这主要用于API的自动化测试

  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等等。请指教。如果有人能就此提供正确的指示,那将非常有帮助

谢谢, 布拉德

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我遇到了同样的问题,needle对我有用。

import os
import shutil

src = r'srcdir'
dest = r'destdir'

for path, subdirs, files in os.walk(src):
    for name in files:
        filename = os.path.join(path, name)

        if 'posted' in filename:
            full_dest_path = os.path.join(dest, filename.lstrip(src).lstrip('/'))

            dirname = os.path.dirname(full_dest_path)
            if not os.path.exists(dirname):
                os.makedirs(dirname)

            shutil.copy2(filename, full_dest_path)

相关问题