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.
Before coding ,i've tried in postman successfully,just adding Header"Content-Type=application/x-www-form-urlencoded" with x-www-form-urlencoded body .
Here is my code:`
RestAssured.baseURI="****"
RequestSpecification request = RestAssured.given().config(RestAssured.config()
.encoderConfig(EncoderConfig.encoderConfig()
.encodeContentTypeAs("x-www-form-urlencoded",
ContentType.URLENC)))
.contentType(ContentType.URLENC.withCharset("UTF-8"))
.formParam("grant_type", *)
.formParam("code", *)
.formParam("client_id",*)
.when().log().all()
.then().log().all().request()
request.post("/oauth2/token")`
I guess rest assured posted as formParam not "x-www-form-urlencoded"? This is rest assured log: `
Request method: POST
Request URI: ***
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: grant_type=***
code=***
client_id=***
Path params: <none>
Headers: Accept=image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 405 Method Not Allowed
Content-Length: 61
Date: Tue, 30 Jan 2018 06:59:20 GMT
X-Correlationid: 5d155b6f-0d85-4775-5f50-82c397e5b44b
X-Smp-Log-Correlation-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b
X-Vcap-Request-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b
Only support Content-Type:application/x-www-form-urlencoded
` This problem drives me crazy for a couple f days . Please do let me know is there any other way to send x-www-form-urlencoded parameters or some updation required in code.
Thanks a lot!