"invalid content type header"
Hello,
can anyone help to share what is wrong on this basic code?: ` function getYoutubeLink(input) { var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://co.wuk.sh/api/json', false); // false for sync, true for async
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Accept', 'application/json');
xhr.send(JSON.stringify({ "url": "https://www.youtube.com/watch?v=1i0k3rjXu9E"}));
//xhr.send(JSON.stringify({ "url": "https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1i0k3rjXu9E"})); // same error
// now it waits for responce, and then do the following script:
if (xhr.readyState === XMLHttpRequest.DONE) {
try { JSON.parse(xhr.responseText.toString()); }
catch (exception) { console.log(link + " // " + "Return message is NOT Json: " + xhr.responseText.toString()); return; }
//var arr = JSON.parse(xhr.responseText.toString());
console.log(xhr.responseText.toString()); } }`
i keep getting: {"status":"error","text":"invalid content type header"}
thos, if I set the Accept header first (before Content-Type), the error say "invalid accept header".. so it looks like JS is only remembering the last header I set...
there is not much do pick up from, documentation does not show example, and anything I could google up "co.wuk.sh" is: https://greasyfork.org/zh-CN/scripts/483370-simple-youtube-downloader/code https://github.com/surenjanath/Spotify-Playlist-Download/blob/main/Spotify%20Music%20Downloader%20Medium%20Article.ipynb
i can't reproduce this, the snippet above just works for me
The snippet also works for me. Try maybe using fetch.