- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用以下代码将 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 只有一个标签页。
最佳答案
当几毫秒内有很多请求时,服务器会失败,服务器端没有人响应。
摘要:服务器端故障。
关于javascript - 上传 multipart/form-data 是随机通过和失败的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46826523/
根据HTML specs : If the contents of a file are submitted with a form, the file input should be identif
我能够找到很多关于 multipart/form-data 的信息,但关于 multipart/related 的信息却不多。在协议(protocol)/请求格式方面,谁能解释一下这两个http规范在
我尝试从项目详细信息页面添加图像。图像添加成功,但是当我尝试在 itemdetails 页面显示图像时,出现异常 org.springframework.web.multipart.Multipart
在 Spring Boot 中,对于分段上传,我看到许多教程站点都建议具有以下属性之一:spring.http.multipart.enabled=false或者spring.servlet.mult
我正在尝试向服务器发送多部分请求,但出现以下异常 HTTP 状态 500 - 请求处理失败;嵌套异常是 org.springframework.web.multipart.MultipartExcep
情况: 从 Node.js(通过 Node 核心 HTTPS 模块)向 spring-boot Java API 提交多部分表单请求。 API 需要两个表单数据元素: “路线” "file" 完全错误
上传到 webapi Controller 时,我仅在某些文件上收到错误。 错误是“MIME 多部分流。MIME 多部分消息不完整” 似乎该错误与某种未良好终止的 POST 数据相关联,但当我使用 f
我有一个有效的解决方案,但似乎很愚蠢,需要它。 这是我的工作解决方案: @PreAuthorize("isAuthenticated()") @ApiOperation(value = "Takes
这个问题已经有答案了: How can I upload files to a server using JSP/Servlet and Ajax? (4 个回答) 已关闭2 年前。 我尝试用java
我尝试通过包含的 CURL 发布 multipart/form-data, A JSON Object Stream object pdf and jpeg file curl -i -X POS
我在表单帖子中遇到了土耳其语字符问题, 我在尝试以下代码时遇到问题, // some input 但是当我尝试这个时它工作正常 // some input 为什么会这样? 最佳答案 在第一个示
我花了几天时间让 Spring Boot Upload 文件工作,但是,和 Spring 一样,你不知道魔法是如何工作的,即使在使用这个框架多年之后 - 你必须用谷歌搜索大量时间来解开哪里出了问题并解
我正在编写一个脚本,用于将文件上传到需要多部分请求的 cgi 脚本,例如 HTML 页面上的表单。 boundary 是一个唯一的标记,用于注释请求正文中的文件内容。这是一个示例正文: --BOUND
我有一个带有 Netty 的 jersy 2.13 的服务器应用程序,我尝试上传带有“multipart/form-data”的文件,但出现此错误。 错误信息: 7605 10:01:49.309
来自文档:“当您使用 TransferManager 下载文件时,该实用程序会自动确定对象是否为多部分” 来源:https://aws.amazon.com/fr/blogs/developer/pa
我需要有关发送多部分发布请求的帮助。主要问题是服务器无法识别我请求的帖子正文部分。服务器端在 android 上运行良好,但在 Qt 和 NetworkAccessManager 上运行不佳。 代码如
在 fragment B 中,我有一个用于将图像提交到服务器的提交按钮。单击提交按钮时,它将返回到 fragment A。我使用 Multipart 将图像上传到服务器,并且该进程在 Thread 上
我目前正在使用 Spring Boot v1.3.0.BUILD-SNAPSHOT 和 Spring v4.2.2.BUILD-SNAPSHOT。 如果我尝试执行多文件上传(通过 angular):
当我使用 JavaMailSender 发送带有附件的电子邮件时,它总是失败并抛出以下异常: org.springframework.mail.MailSendException: Failed me
我正在尝试在 NodeJS 上手动解析 multipart/formdata 请求。 请求中的所有内容均已正确解析(文件除外)。我正在读取文件数据,但它的长度比原始的短(在fiddler中,选择hex
我是一名优秀的程序员,十分优秀!