How to send x-www-form-urlencoded keyValue pair parameters

2,204 views
Skip to first unread message

Sumit Bhardwaj

unread,
Jan 16, 2018, 2:15:50 AM1/16/18
to REST assured
Hi,

I have a post request where i need to send x-www-form-urlencoded keyValue pair parameters and content-type should be x-www-form-urlencoded.

If i look to post man it will look like below


I am using below code:

RestAssured.baseURI = "https://ww.abc.com";

         RequestSpecification request = RestAssured.given().log().all().config(RestAssured.config()
         .encoderConfig(EncoderConfig.encoderConfig()
         .encodeContentTypeAs("x-www-form-urlencoded",
         ContentType.URLENC)))
         .contentType("x-www-form-urlencoded")
          .formParam("abc", "def")
          .formParam("hij", "xyz")
          .formParam("123", "456")
          .formParam("789", "222")
          .formParam("password", "abc")
         .header("accept", "application/json")
         .header("123", "abc")
         .header("456", "ttt")
         .header("channel", "1111").request();

Response res = request.post("/111");

When i check RestAssured logs it shows all parameters in Form params but parameters are sent as form-data not as x-www-form-urlencoded parameters.
Please do let me know is there any other way to send x-www-form-urlencoded parameters or some updation required in code.

Thanks in advance.
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Sumit Bhardwaj

unread,
Jan 16, 2018, 2:17:53 AM1/16/18
to REST assured
Added larger images.


Auto Generated Inline Image 1
Auto Generated Inline Image 2

Sumit Bhardwaj

unread,
Jan 16, 2018, 4:05:58 AM1/16/18
to REST assured
finally find the fix, what is missed is to set charset UTF-8 in content type, after adding that it works fine.
Reply all
Reply to author
Forward
0 new messages