首页   注册   登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
华为云
V2EX  ›  程序员

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

  •  
  •   wsds · 96 天前 · 720 次点击
    这是一个创建于 96 天前的主题,其中的信息可能已经有所发展或是发生改变。

    浏览器中:

    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--
    

    1 3 abc

    
    
    ```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)
    
    
    7 回复  |  直到 2018-05-16 19:19:03 +08:00
        1
    2DaYe   96 天前
    你把 head 写到 parameter 里了
        2
    wsds   96 天前
    @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--
        3
    mypchas6fans   96 天前
    仅从这个 exception 看,我怀疑是最后一张图 File Upload 里面,MIME 类型应该是 image/png
        4
    mypchas6fans   96 天前
    说错了,是 image/jpeg。并且参数名称那里应该是“ file ”。
    Parameters 这个 tab 里的 3 行参数可能都不需要
        5
    wsds   96 天前
    @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"}
        6
    mypchas6fans   96 天前
    看看结果树里面请求的内容吧,如果确实没有 boundary,把那个 use multipart/for-data for post 勾掉,然后自己加一个 http header:
    名称 Content-Type
    值 multipart/form-data; boundary=----WebKitFormBoundarya9MF0hb2gtA3RQ0K
        7
    glacer   96 天前
    multipart 上传文件
    关于   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   2691 人在线   最高记录 3762   ·  
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.1 · 23ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    ♥ Do have faith in what you're doing.
    沪ICP备16043287号-1