发出POST请求时重定向

时间:2018-09-12 01:09:28

标签: javascript npm-request

我正在处理这段代码,该代码向端点发出POST请求,然后应该使用简单的JSON进行响应。这是我的代码:

var businessRulesOptions = {
  method: 'POST',
  followAllRedirects: true,
  url: 'https://bpmrulesruntimebpm-*************hanatrial.ondemand.com/rules-service/v1/rules/invoke',
  qs: { rule_service_name: 'IoTManager::TemperatureService' },
  headers:
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     'x-csrf-token': '*******************************' },
  body: [
    {   _type_: 'IoTManagerDataObjects',
        Temperature: 55
    } ],
  json: true };

request(businessRulesOptions, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

此代码是由邮递员生成的,并且可以通过邮递员完美地工作。但是,当我尝试通过命令行运行它时,它将返回以下响应。

   <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="viewport" content="width=device-width, initial-scale=1.
0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"><meta http-equiv="pragma" content="no-cache" /></head><body style="background-color:#FFFFFF" onload="var url=window.location.hash;if(url&&0!==url.length){var anchorCooki
e='oucrsmziosknqgbubpwdsbwds_anchor=&quot;'+encodeURIComponent(url)+'&quot;';document.cookie=anchorCookie}document.forms[0].submit()"><p><script language="javascript">document.write("Please wait ...");</script></p><noscript><p>
Note: Your browser does not support JavaScript or it is turned off. Press the button to proceed.</p></noscript><form method="post" action="https://accounts.sap.com/saml2/idp/sso/accounts.sap.com"><input type="hidden" name="SAML
Request" value="PEF1dGhuUmVxdWVzd..."/><input type="hidden" name="RelayState" value="oucrsmziosknqgbubpwdsbwds"/><noscript><input type="submit" value="Continue"/></noscript></form><
/body></html>

我查找了此错误,似乎与发出POST请求时的重定向有关。我添加了followAllRedirects: true,但还是没有运气。

我们将不胜感激:)

0 个答案:

没有答案