简体   繁体   中英

Why do I keep on getting 400 Bad Request

{
  method: 'POST',
  url: 'https://wandbox.org/api/compile.json',
  compiler: 'cpython-3.8.0',
  code: 'print("hello")',
  headers: { 'Content-Type': 'application/json' }
}

When I have this as "options" and I do:

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);
                  })

the body is nothing and in httpResponse I get

  statusCode: 400,
  statusMessage: 'Bad Request',

why is that? what is wrong with my request? I am trying to follow https://github.com/melpon/wandbox/blob/master/kennel2/API.rst but nothing seems to work. How can I fix my request?

You aren't sending the parameters as a JSON string as you should.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM