使用GM_xmlhttprequest将图像上传到API

时间:2017-08-24 16:05:01

标签: javascript xmlhttprequest greasemonkey userscripts gm-xmlhttprequest

对于我的用户脚本,我尝试使用 GM_xmlhttprequest

函数将图像作为POST请求上传到http://www.noelshack.com/api.php
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!"
  }
});

我做错了什么?我应该以特定格式编码文件吗?没有 Noelshack API的文档...

0 个答案:

没有答案