我开发了一个休息服务器,并将其在本地主机中运行,我尝试使用 JMeter 执行测试,发送请求帖子和获取(取决于调用的方法)。
我已经发送到 Rest 服务器并使用 JMeter 在简单的 post 请求、获取请求、通过 post 发送文件以及通过 post 发送 Json 中获得结果。
但我不知道如何将
Form-UrlEncoded
对象发送到服务器。我的Rest服务器消耗application/x-www-form-urlencoded
,我需要发送3个字符串参数。
有某种方法可以为每个参数设置
MimeType
并执行测试吗?
我使用的是Jmeter 2.7
我通过禁用该选项解决了这个问题:
use multipart/form-data for post
并启用:
redirect automatically
代替:
follow redirect
我通常将参数放在“随请求发送参数”表中,并带有各自的名称。
要将表单参数作为 application/x-www-form-urlencoded 发送,请添加一个标头参数 Content-Type,其值为 application/x-www-form-urlencoded。
以下步骤适用于Jmeter 2.3.4
将 HTTP 请求的“内容编码:”文本框保留为空。
这不适用于 PUT 请求。 对于 put 请求,添加参数作为路径参数并设置 Content-Type 标头,然后 Jmeter 将自行完成。
您是否尝试过使用 BadBoy 或 JMeter Proxy 保存测试以查看应用程序实际发送的内容?
要查看幕后发生的情况,您还可以使用
FireBug
(如果您使用的是 FireFox)或 Ctrl+Shift+i
(如果您使用的是 Chrome)。
IllegalCharsetNameException 才会立即发生。
希望这有帮助。
按照提到的确切步骤操作,我仍然看到抛出异常
响应代码:非 HTTP 响应代码:java.nio.charset.IllegalCharsetNameException 响应消息:非HTTP响应消息:application/x-www-form-urlencoded
java.nio.charset.IllegalCharsetNameException: application/x-www-form-urlencoded
at java.nio.charset.Charset.checkName(Charset.java:315)
at java.nio.charset.Charset.lookup2(Charset.java:484)
at java.nio.charset.Charset.lookup(Charset.java:464)
at java.nio.charset.Charset.forName(Charset.java:528)
at org.apache.http.entity.ContentType.create(ContentType.java:210)
at org.apache.http.entity.StringEntity.<init>(StringEntity.java:116)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPostData(HTTPHC4Impl.java:1340)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.handleMethod(HTTPHC4Impl.java:592)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:409)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1166)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1155)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:475)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249)
at java.lang.Thread.run(Thread.java:745)