gpt4 book ai didi

javascript - 上传 multipart/form-data 是随机通过和失败的

转载 作者:行者123 更新时间:2023-12-03 08:29:39 31 4
gpt4 key购买 nike

我使用以下代码将 multipart/form-data 上传到服务器:

<!DOCTYPE html>
<html>
<body>
<form >
<input id="file" type="file" name="file" multiple><br>
</form>
<button id="ajax_submit">ajax_submit</button>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<script>
$( "#ajax_submit" ).click(function()
{
//alert( "Handler for .click() called." );
var i = 0;
while (i < document.getElementById('file').files.length)
{

var data = new FormData();


//alert("before" + i);
data.append('file', document.getElementById('file').files[i]);//first string parameter indicate the input field to name for server side
//alert("after" + i);

jQuery.ajax({
url: 'http://xx.xxx.xx.xxx:8080/sign',
data: data,
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST', // For jQuery < 1.9
success: function(data)
{
//alert(data);
}
});
i++;
}
});
</script>
</body>
</html>

问题是当一次选择多个文件时,获得成功响应的概率非常低,而当我选择一个文件时它有更高的概率。

当它成功时,我在 Chrome 上得到了以下请求和响应 header :

Genaral
Request URL:http://xx.xxx.xx.xxx:8080/sign
Request Method:POST
Status Code:200
Remote Address:xx.xxx.xx.xxx:8080
Referrer Policy:no-referrer-when-downgrade
Response Headers
Date:Thu, 19 Oct 2017 08:50:08 GMT
Transfer-Encoding:chunked
X-Application-Context:application
Request Headers
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:33274
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryOuscIdBAA52VbAZK
Host:xx.xxx.xx.xxx:8080
Origin:null
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Request Payload
------WebKitFormBoundaryOuscIdBAA52VbAZK
Content-Disposition: form-data; name="file"; filename="text.pdf"
Content-Type: application/pdf

当我失败时,我在 Safari 和 Chrome 浏览器上收到以下错误消息请求和响应 header :

Chrome:

Genaral    
Request URL:http://xx.xxx.xx.xxx:8080/sign
Referrer Policy:no-referrer-when-downgrade
Request Headers
Provisional headers are shown
Accept:*/*
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryAmGAPOT6r0Voe5mr
Origin:null
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Request Payload
------WebKitFormBoundaryAmGAPOT6r0Voe5mr
Content-Disposition: form-data; name="file"; filename="empty.pdf"
Content-Type: application/pdf

POST http://xx.xxx.xx.xxx:8080/sign net::ERR_CONNECTION_REFUSED send @ jquery-3.2.1.min.js:4 ajax @ jquery-3.2.1.min.js:4 (anonymous) @ multiplefileHandler.html:26 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:4

POST http://xx.xxx.xx.xxx:8080/sign net::ERR_CONNECTION_RESET send @ jquery-3.2.1.min.js:4 ajax @ jquery-3.2.1.min.js:4 (anonymous) @ multiplefileHandler.html:26 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3


Safari :

Failed to load resource: The network connection was lost.

Failed to load resource: Could not connect to the server.


当我尝试使用 Java Apache HTTP 客户端调用时出现以下错误:

org.apache.http.NoHttpResponseException: xx.xxx.xx.xxx:8080 failed to respond

当我使用 Chrome 选择 8 个文件并按下 ajax_submit 按钮时,事件监视器的屏幕截图。当时 Chrome 只有一个标签页。 enter image description here

最佳答案

当几毫秒内有很多请求时,服务器会失败,服务器端没有人响应。

摘要:服务器端故障。

关于javascript - 上传 multipart/form-data 是随机通过和失败的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46826523/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com