jmeter 模拟页面上传图片, payload 究竟怎么传递才正确?各种传递,都是 500

2018-05-16 13:11:02 +08:00
 wsds

浏览器中:

Request URL: http://192.168.11.193:8083/api/xxx/image/upload/true?type=1
POST /api/intellif/image/upload/true?type=1 HTTP/1.1
Host: 192.168.11.193:8083
Connection: keep-alive
Content-Length: 6742
Pragma: no-cache
Cache-Control: no-cache
Authorization: Bearer 147e9f25-3fb1-42fb-bc05-21b2e5c8b501
Origin: http://192.168.11.193:8066
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarya9MF0hb2gtA3RQ0K
Accept: */*
Referer: http://192.168.11.193:8066/app/userManagement/newStudentsManagement
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7

Request Payload:

------WebKitFormBoundarya9MF0hb2gtA3RQ0K
Content-Disposition: form-data; name="file"; filename="2018-02-27-14-08-56-478_format_f.jpg"
Content-Type: image/jpeg


------WebKitFormBoundarya9MF0hb2gtA3RQ0K--



```java
java.lang.IllegalArgumentException: MIME type may not contain reserved characters
	at org.apache.http.util.Args.check(Args.java:36)
	at org.apache.http.entity.ContentType.create(ContentType.java:227)
	at org.apache.http.entity.ContentType.create(ContentType.java:239)
	at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:85)
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$ViewableFileBody.<init> 
        (HTTPHC4Impl.java:1240)
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPostData(HTTPHC4Impl.java:1313)
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.handleMethod(HTTPHC4Impl.java:629)
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:450)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1189)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1178)
	at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490)
	at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416)
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250)
	at java.lang.Thread.run(Unknown Source)

3842 次点击
所在节点    程序员
8 条回复
2DaYe
2018-05-16 13:15:54 +08:00
你把 head 写到 parameter 里了
wsds
2018-05-16 13:19:39 +08:00
@2DaYe
Request Payload:

------WebKitFormBoundarya9MF0hb2gtA3RQ0K
Content-Disposition: form-data; name="file"; filename="2018-02-27-14-08-56-478_format_f.jpg"
Content-Type: image/jpeg


------WebKitFormBoundarya9MF0hb2gtA3RQ0K--
mypchas6fans
2018-05-16 14:18:24 +08:00
仅从这个 exception 看,我怀疑是最后一张图 File Upload 里面,MIME 类型应该是 image/png
mypchas6fans
2018-05-16 14:23:37 +08:00
说错了,是 image/jpeg。并且参数名称那里应该是“ file ”。
Parameters 这个 tab 里的 3 行参数可能都不需要
wsds
2018-05-16 14:42:00 +08:00
@mypchas6fans
改了,报错不一样了
{"timestamp":1526452878375,"status":500,"error":"Internal Server Error","exception":"java.lang.RuntimeException","message":"java.lang.RuntimeException: java.io.IOException: Missing initial multi part boundary","path":"/api/intellif/image/upload/true"}
mypchas6fans
2018-05-16 15:28:34 +08:00
看看结果树里面请求的内容吧,如果确实没有 boundary,把那个 use multipart/for-data for post 勾掉,然后自己加一个 http header:
名称 Content-Type
值 multipart/form-data; boundary=----WebKitFormBoundarya9MF0hb2gtA3RQ0K
glacer
2018-05-16 19:19:03 +08:00
multipart 上传文件
wsds
2019-02-18 19:57:32 +08:00
@Livid @Kai @Olivia @GordianZ @sparanoid
麻烦帮我删除此帖,多谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/455256

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX