1

对于我的用户脚本,我正在尝试使用函数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没有文档...

4

0 回答 0