Search code examples
rest-assured

Swagger Get API return HTML for static distribution bundle build using RestAssured instead of JSON Response. Works fine with CURL


Stuck with one issue which I am facing with RestAssured to validate one GET call on Swagger BookStore API. It’s working fine in Curl.

Working CURL command:

curl -X GET “https://bookstore.toolsqa.com/Account/v1/User/f00600d9-dc34-46e7-84f1-9404410b7f74” -H “accept: application/json” -H “authorization: Basic Qm9va1Rlc3RlcjEyOlRlc3RlciMxMg==”

AND it returns JSON response as expected.

Now, I am calling same API using RestAssured with code as below:

RestAssured.given().header(“accept”, “application/json”)
.header(“authorization”, “Basic Qm9va1Rlc3RlcjpUZXN0ZXIjMTI=”)
.when()
.get(“https://bookstore.toolsqa.com/Account​/v1​/User​/5641c9d9-1e3f-45be-a752-e1cc9d31e151”);

But it’s not giving any JSON response but HTML default page.


Solution

  • Maybe your code contains 'ZWSP​​' but you cannot see it on your IDE.

    I saw it when copying your code to Intellij. Remove these, and the code worked fine.

    enter image description here

    RestAssured.given().header("accept", "application/json")
            .header("authorization", "Basic Qm9va1Rlc3RlcjpUZXN0ZXIjMTI=")
            .when()
            .get("https://bookstore.toolsqa.com/Accoun/v1/User/5641c9d9-1e3f-45be-a752-e1cc9d31e151")
            .prettyPrint();