Search code examples
javarestrest-assuredhttp-status-code-303

Rest assured throws ClientProtocolException when the status code is 303


In my workplace we are using rest assured 2.9 to send rest API requests, I'm getting a valid output containing both response body and status code even if the status code is 500,402.

BUT the only case this isn't working is error 303 See Other, I'm getting Method threw org.apache.http.client.ClientProtocolException exception and I can't parse the information that way, all the other status codes are returning status code and body, only 303 throws exception. The API isn't the problem, because sending the API through post man work as expected, the call is

given()
 .body(body.toString())
 .post(url);

Solution

  • Use: redirects().follow(false)

    For example: given().redirects().follow(false).body(body.toString()).post(url);