Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fetch cannot change content type to application/json

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The key to add headers with fetch API is headers. In your code you have used header instead of headers.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading