Rest-Assured doesn't redirect post-requests

17 views
Skip to first unread message

Harshal Chopade

unread,
Mar 25, 2022, 4:11:27 AMMar 25
to REST assured
Hi All,

I have a question if anyone has any experience the below issue with redirect post-requests

I am trying to hit an post API using Rest-Assured.

The same API hit (with same header data) works fine from Postman but while hitting the request from Rest-Assured, I always receive following response:

307 Temporary Redirect

Below is the method am using

public Response post(String path, HashMap<String, String> headers, String payload, int statusCode,
HashMap<String, String> validations) throws Exception {
String contentType = "";
if (headers.get("Content-Type") != null) {
contentType = headers.get("Content-Type");
headers.remove("Content-Type");
} else if (headers.get("content-type") != null) {
contentType = headers.get("content-type");
headers.remove("content-type");
}
Response returnResponse;
returnResponse = given()
.config(RestAssured.config()
.encoderConfig(new EncoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
.relaxedHTTPSValidation().contentType(contentType).filter(new RestAssuredRequestFilter())
.headers(headers).body(payload).post(host + path);
return returnResponse;
}  

If you have a solution or experience feel free to suggest

Thanks
Reply all
Reply to author
Forward
0 new messages