适用于Postman但不适用于VS代码的HTTP发布请求

时间:2019-11-08 15:23:02

标签: javascript json

我有一个播放语音消息的http POST请求,它可以完美地处理邮递员和字幕文本,但不适用于vscode。

<script type="text/javascript">
  var request = require('request');
  //process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

  var headers = {
    'Authorization': 'Basic YWRtaW46RHVubG9wMjAxNyo=',
    'Content-Type': 'application/json'
  }
  var options = {
    json: true,
    url: 'https://srusa.local/10.11.208.10:8444/InformaCast/RESTServices/V1/Messages/2147483943' +
      '?Authorization= Basic YWRtaW46RHVubG9wMjAxNyo=',
    method: 'POST',
    headers: headers,
    body: {
      "recipients":  [{
        "id": "2147483942",
        "type": "RECIPIENT_GROUP"
      }]
    }
  };

  function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log(body);
    }
  }

  request(options, callback);
</script>

</head>

<body>
  <center>
    Javascript Post Request Test
  </center>
</body>

</html>

1 个答案:

答案 0 :(得分:1)

授权应该是标题,而不是URL参数。