JS FileTransfert return Http 411

JS FileTransfert return Http 411

本文关键字:Http return FileTransfert JS      更新时间:2024-02-02

我正在尝试更新配置文件图片,它在本地服务器上工作,但在远程服务器上不工作,在最后一个上,我收到了Http 411响应

function imageReceived(imageURI) { // this is done after taking a picture
  var options = new FileUploadOptions();
      options.fileName = 'profilePic.jpg';
      options.headers = {Authorization: 'Token token=' + profile.accessToken};
  var ft = new FileTransfer();
  ft.upload(imageURI,
     url("/api/v1/update_avatar"), // url() is a function that returns the full path
     function(result) {
       alert(result);
     },
     function(error) {
         alert( JSON.stringify(error));
     },
     options);
}

PS:

  • profile是我已经拥有的类,accessToken具有正确的值
  • 本地服务器是HTTP,远程服务器是HTTPS,这有区别吗

我做错了什么或错过了什么??

任何帮助都将不胜感激!!

您必须将Content-Length标头与请求一起发送。

发件人http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html:

411 Length Required
The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.

正如您在这篇文章中所看到的,您将不得不与您的托管公司进行讨论。

Web服务器(运行网站)认为HTTP数据流由客户端发送(例如您的Web浏览器或我们的CheckUpDown机器人)应包括"内容长度"规范。这通常是仅用于导致在Web服务器,而不是从中检索数据。

修复411个错误-通用

此错误很少出现在大多数Web流量中,尤其是当客户端系统是一个Web浏览器。问题只能通过以下方式解决检查您的客户端系统正在尝试做什么,然后与讨论您的ISP为什么Web服务器需要"内容长度"规范。