For my userscript I'm trying to upload an image to http://www.noelshack.com/api.php as a POST request, using the function GM_xmlhttprequest
var file = document.getElementById("MyFileInput").files[0];
GM_xmlhttpRequest({
method: "POST",
url: "http://www.noelshack.com/api.php",
data: file,
headers: {
"Host": "www.noelshack.com",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
"Accept-Encoding": "gzip, deflate",
"Cookie": "wbCookieNotifier=1",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1"
},
onload: function(resp) {
alert(resp.status); // 200
alert(resp.responseText); // "An error has occured during file transfer!"
}
});
What am I doing wrong? Should I encode the file in a specific format? There are no documentation for the Noelshack API...