JMeter File Upload with HTTP Put Method Not Working

江枫思渺然 提交于 2019-12-12 15:18:22

问题


The idea is to build a sampler in JMeter that will upload a file using the HTTP PUT method. I'm trying to follow the official documentation to specify the entire content body as a file with no parameter name.

  • What should happen: The file gets uploaded and the server returns 201: created
  • What actually happens:

java.lang.NullPointerException: charsetName at java.lang.String.<init>(Unknown Source) at java.lang.String.<init>(Unknown Source) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPutData(HTTPHC4Impl.java:1067) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:274) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1054) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1043) at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:416) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:271) at java.lang.Thread.run(Unknown Source)

This seems to indicate that JMeter has a problem with filling out the body of a request. I can get rid of this error by specifying a parameter with the request, but I want the entire body to be the photo data. Here's the CURL line of what I want accomplished:

curl -u testuser:testpass "http://localhost:8080/photo" -T photo.jpg -H "content-type:image/jpeg"

I've tried setting the content-encoding to UTF-8 as I've seen in one post, but that changed nothing.

I'm running Java 1.7.0 on Windows 7 x64. Nothing of interest gets generated in jmeter.log, and wireshark tells me that JMeter isn't sending the request.

Any ideas? Thanks in advance.


回答1:


Turns out it was a bug that the nice folks at JMeter were able to fix very quickly: https://issues.apache.org/bugzilla/show_bug.cgi?id=52897

Using the nightly build solved my problem, and by now it has probably made it into the release.




回答2:


Use Raw HTTP Request to accomplish this. You may specify headers in Request Data and also specify file containing PUT body for convinience.

Some details may be found here




回答3:


I was having issues with image uploads and found the answers here https://stackoverflow.com/a/2115944/455363. After making the suggested changes here I had to re-record the transaction and make my edits and I was successfully able to upload files.

Hope this helps.



来源:https://stackoverflow.com/questions/9672706/jmeter-file-upload-with-http-put-method-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!