Some developer who does not know proper json format is key value pair made the json body just a string so it looks like this: { "dog" }
rather than { "dog": "dog" }
I need to send the request from a javascript file and the body must be JSON. I have tried sending raw JSON with Ajax, fetch, Axios, and xmlHttp but they are all formatting it into key value pair. How should I send this request?
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'text/plain',
},
body: '{ "dog" }'
})
This will send the string { "dog" }
in the body, if that is what the endpoint you are trying to use expects. Just... don't call it JSON. It's as much a JSON as pudding is a hammer.
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.