Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to follow the redirect in rest assured?

Tags:

rest-assured

I have a spring boot application and a controller will redirect to a page based on the post parameter.
And I am creating the test case which want to assert the redirect page But I failed to get the redirected html from the rest assured response

    @Test
    public void test() throws Exception {

        Response response = given()
            .param("name", "myName")
        .when()
            .redirects().follow(true).redirects().max(100)
            .post("/myPath");      // it will redirect to another page


        // I want to print from <html> to </html> of the redirected page
        System.out.println("returned full html /n" + response.getBody().asString());  
    }

I receive 302 and the location of the redirect page in the response header.

11:38:03.291 [main] DEBUG org.apache.http.headers - << "Location: http://localhost:8080/myRedirectPage[\r][\n]"
.........
11:38:03.291 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 302 
11:38:03.291 [main] DEBUG org.apache.http.headers - << HTTP/1.1 302 
like image 404
brian661 Avatar asked Feb 27 '17 08:02

brian661


People also ask

How do I follow a postman redirect?

To do this, open the Settings tab of your request and toggle off the Automatically follow redirects option. Force your request to follow the original HTTP method. To do so, open the Settings tab of the request and toggle on the Follow original HTTP method option.

How does API redirect work?

redirect() The redirect() method of the Response interface returns a Response resulting in a redirect to the specified URL. Note: This is mainly relevant to the ServiceWorker API. A controlling service worker could intercept a page's request and redirect it as desired.

What is redirect response?

In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start with 3 , and a Location header holding the URL to redirect to. When browsers receive a redirect, they immediately load the new URL provided in the Location header.

What is redirect with example?

A redirect is when a web page is visited at a certain URL, it changes to a different URL. For instance, a person visits “website.com/page-a” in their browser and they are redirected to “website.com/page-b” instead.


1 Answers

I had similar issue, "post" with status code 302 and 307 is not supported for rest assured redirect. Either we have to change to "get" or "post" with 303 status code. More information click here

like image 102
Manjunatha Thippeswamy Avatar answered Sep 23 '22 07:09

Manjunatha Thippeswamy