【问题标题】:Why do I keep on getting 400 Bad Request为什么我不断收到 400 Bad Request
【发布时间】:2021-02-02 11:36:24
【问题描述】:
{
  method: 'POST',
  url: 'https://wandbox.org/api/compile.json',
  compiler: 'cpython-3.8.0',
  code: 'print("hello")',
  headers: { 'Content-Type': 'application/json' }
}

当我将其作为“选项”并且我这样做时:

request.post(options, function optionalCallback(err, httpResponse, body) {
                    if (err) {
                      return console.error('upload failed:', err);
                    }
                    console.log(body)
                    console.log('Upload successful!  Server responded with:', httpResponse);
                  })

body 什么都不是,在 httpResponse 中我得到了

  statusCode: 400,
  statusMessage: 'Bad Request',

这是为什么呢?我的要求有什么问题?我正在尝试关注https://github.com/melpon/wandbox/blob/master/kennel2/API.rst 但似乎没有任何效果。如何解决我的请求?

【问题讨论】:

    标签: node.js http-post


    【解决方案1】:

    您没有按照应有的方式将参数作为 JSON 字符串发送。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-11
      • 2019-04-20
      • 2015-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多