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

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

  •  
  •   wsds · 2018-05-16 13:11:02 +08:00 · 3925 次点击
    这是一个创建于 2378 天前的主题,其中的信息可能已经有所发展或是发生改变。

    浏览器中:

    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)
    
    
    8 条回复    2019-02-18 19:57:32 +08:00
    2DaYe
        1
    2DaYe  
       2018-05-16 13:15:54 +08:00
    你把 head 写到 parameter 里了
    wsds
        2
    wsds  
    OP
       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
        3
    mypchas6fans  
       2018-05-16 14:18:24 +08:00
    仅从这个 exception 看,我怀疑是最后一张图 File Upload 里面,MIME 类型应该是 image/png
    mypchas6fans
        4
    mypchas6fans  
       2018-05-16 14:23:37 +08:00
    说错了,是 image/jpeg。并且参数名称那里应该是“ file ”。
    Parameters 这个 tab 里的 3 行参数可能都不需要
    wsds
        5
    wsds  
    OP
       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
        6
    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
        7
    glacer  
       2018-05-16 19:19:03 +08:00
    multipart 上传文件
    wsds
        8
    wsds  
    OP
       2019-02-18 19:57:32 +08:00
    @Livid @Kai @Olivia @GordianZ @sparanoid
    麻烦帮我删除此帖,多谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5525 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:19 · PVG 15:19 · LAX 23:19 · JFK 02:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.