My http request got 415 error and checked why, I set it’s content type to json but it’s not applying.
let data = {
id: category.id,
act: "addAdmin",
target: input,
};
fetch("http://localhost:8888/categoryset", {
method: "POST",
header: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
and this is Request Headers as result..
POST /categoryset HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Content-Length: 37
Content-Type: text/plain;charset=UTF-8 <--- NOT APPLIED!
Cookie: JSESSIONID=C9AEA57BE4C4C23657E6ADD77D75AD7D
DNT: 1
Host: localhost:8888
Origin: http://localhost:8888
Referer: http://localhost:8888/control/category
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 OPR/91.0.4516.77
sec-ch-ua: "Not-A.Brand";v="99", "Opera";v="91", "Chromium";v="105"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
>Solution :
The key to add headers with fetch
API is headers
. In your code you have used header
instead of headers
.