1
votes

I tried to generate the token from login request.It is successful in postman tool and success in soapui groovy script.But I couldnot do via rest assured library.Below are the screenshot where the request uses Body - form-data with username and password. enter image description here

I have tried the using queryparams, formparam but getting the below error.Kindly help me to solve the error.

    <html>
    <head><title>301 Moved Permanently</title></head>
    <body bgcolor="white">
    <center><h1>301 Moved Permanently</h1></center>
    <hr><center>nginx/1.4.4</center>
    </body>
    </html>

Rest assured code:

    Map<String, String> formParams = new HashMap<>();
            formParams.put("username", "test");
            formParams.put("password", "welcome");

            Response response = RestAssured.given().config(RestAssured.config().redirect(redirectConfig().followRedirects(false)).encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.TEXT)))
                .queryParams(formParams)
                .post("http://posturl");
1
Post your rest-assured code please - without that it is hard to help. - kenny_k
Hi Kenny , I have appended the code - user3350712

1 Answers

0
votes

You are sending the parameters as a query, not as form params.

Also, looks like you need to follow the redirect, since you're getting a 301, so you need followRedirects(true) instead of false.

You need to do it this way:

Response response = RestAssured.given()
                .config(RestAssured.config()
                        .redirect(new RedirectConfig().followRedirects(true))
                        .encoderConfig(EncoderConfig
                                .encoderConfig()
                                .encodeContentTypeAs("multipart/form-data", ContentType.TEXT)))
                .formParams(formParams)
                .post("http://posturl");