How send application/x-www-form-urlencoded params to a RestServer with JMeter?
Asked Answered
M

6

17

I developed a rest server, and I put it to run in localhost, and I'm trying to perform tests with JMeter, sending requests posts and gets (depends of called method).

I already send to Rest server and got result with JMeter in simple post requests, get requests, sending files with post, and sending a Json with post.

But I don't know how to send a Form-UrlEncoded object to server. My Rest server consumes application/x-www-form-urlencoded, and I need to send 3 String parameters.

There's some way to set the MimeType for every parameter and perform the test ?

I'm using Jmeter 2.7

  • [Update]

I solved this by disabling the option:

use multipart/form-data for post

And enabling:

redirect automatically

Instead of:

follow redirect

The parameters I put normally in the table "Send parameters with the Request" with each respective names.

Marrissa answered 28/6, 2012 at 18:13 Comment(0)
I
2

Have you tried to save your test using BadBoy or JMeter Proxy to see what your application actually sends?

To see what happens under the hood you can also use FireBug if you're using FireFox or Ctrl+Shift+i if you're on Chrome.

Impoverish answered 28/6, 2012 at 21:59 Comment(1)
also F12 on any current browser will show you the Network chatter.Genous
S
30

For sending form parameters as application/x-www-form-urlencoded, add a header parameter Content-Type with value application/x-www-form-urlencoded.

The following steps is aplicable for Jmeter 2.3.4

  1. Add a HTTP Header Manager under your http Request.
  2. Add new parameter to HTTP Header Manager with name Content-Type and value application/x-www-form-urlencoded.
  3. Uncheck "Use multipart/form-data for HTTP POST" of HTTP request.
  4. Uncheck "Encode?" of each request parameter(not necessary).
  5. kept "Content Encode:" text box of HTTP request as empty.

    This won't work for PUT request. For put request add parameters as path parameter and set Content-Type header then Jmeter will do by itself.

Satisfactory answered 22/7, 2015 at 8:57 Comment(1)
This worked very well. Thanks for sharing these steps.Roseannroseanna
C
14

Here's the solution for HTTP POST with x-www-form-urlencoded testing with jmeter. You just folllow like these. enter image description here

enter image description here

enter image description here

Go to Thread Group -> Add listener -> Views Result in table, View result Tree. To see the process of responding.

Climacteric answered 30/10, 2017 at 8:53 Comment(0)
I
2

Have you tried to save your test using BadBoy or JMeter Proxy to see what your application actually sends?

To see what happens under the hood you can also use FireBug if you're using FireFox or Ctrl+Shift+i if you're on Chrome.

Impoverish answered 28/6, 2012 at 21:59 Comment(1)
also F12 on any current browser will show you the Network chatter.Genous
R
0

IllegalCharsetNameException will go immediately only after you will add the required content-type in HTTP Header Manager for HTTP request .

Hope this helps.

Restore answered 1/12, 2017 at 15:48 Comment(0)
T
0

HTTP Request

HTTP Header Manager

Steps:

  1. Adding the form-data(encoded) in the Parameters TAB in HTTP Request
  2. and the content-type in the Content-Type application/x-www-form-urlencoded in the HTTP Header Manager has solved my issue
Thermic answered 9/4 at 7:5 Comment(0)
L
-3

followed exact steps mentioned i still see an exception thrown

Response code: Non HTTP response code: java.nio.charset.IllegalCharsetNameException Response message: Non HTTP response message: 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)
Loosing answered 17/7, 2017 at 16:13 Comment(3)
It does work after i have upgraded from JMeter 3.1 to 3.2Loosing
This is not an answer to the question at hand. Either take this to chat or post a new question referring to this one.Steffie
It's an answer ain't itLoosing

© 2022 - 2024 — McMap. All rights reserved.