reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Can I somehow force data: to keep the input as pure json

Open bdart opened this issue 9 years ago • 4 comments

Hi is there a way to force the body to stay as a json object? It looks quite strange with this:

var id = JSON.stringify(id)
console.log(id);
request({
    url: TREATMENT_URL,
    method: 'POST',
    crossOrigin: true,
    type: 'json',
    contentType: 'application/json',
    data: {
      id: 1
    }

When I make the POST call the http call does not contain {"id":1} rather it contains this:

Request Payload:
id=%7B%22id%22%3A1%7D

How can I work around to keep it as json :(?

bdart avatar Nov 04 '15 17:11 bdart

I got around this by passing the flag processData: false, and processing it myself, i.e. data: JSON.stringify({ id: 1 }).

buob avatar Dec 14 '15 21:12 buob

not working @buob

Duan112358 avatar Jan 14 '16 15:01 Duan112358

I meet the same issue. If I set processData: true, it will send request body [object,object] ? How can I send the json object like the post in angular $http.post ?

rayzang8 avatar Aug 26 '16 06:08 rayzang8

How have you not solved this yet! I just burnt an hour on this! @buob you are a genius!

bldoron avatar Sep 05 '16 16:09 bldoron