Reputation: 81
fetch(url, {
method: 'post',
headers: {
"Content-type":
},
body: 'bar= foo& lorem=ipsum'
})
Should it be?
A) application/x-www-form-urlencoded; charset=UTF-8
B) text/html; charset=utf-8
C) application/json; charset=UTF-8
D) Content-Type: multipart/form-data; boundry=something
I've just started to learn JavaScript and APis. While looking at MDN docs I found there are different options to put in the headers. Just confused about which one to use?
Upvotes: 0
Views: 1216
Reputation: 182
if you are sending url encoded data (ex: key=value&key=value
) then Content-Type
will be:
if you are sending html data (ex: <h1>hello</h1>
) then Content-Type
will be:
if you are sending json data (ex: {"name" : "anyName"}
) then Content-Type
will be:
if you are sending form data + files (ex: new FormData(document.getElementById('form1'))
) then you don't need to set Content-Type
manually that is:
Upvotes: 1
Reputation: 780974
A sequence of key=value
parameters separated by &
is the URL-encoded format of parameters. So A is the correct answer.
Upvotes: 2