0

I am trying to automate the open source mathjs api which is having the url as "https://api.mathjs.org/v4/?expr=2%2F3&precision=3" . Below is my code

import java.util.TreeMap;
import org.junit.Test;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
public class Mathjs2 {
@Test
public void getResponseBody() {
    RestAssured.baseURI = "https://api.mathjs.org/v4/";
    RequestSpecification httpRequest = RestAssured.given().relaxedHTTPSValidation();
    TreeMap<String, String> temp = new TreeMap<String, String>();
    temp.put("expr", "2%2F3");
    temp.put("precision", "3");
    httpRequest.queryParams(temp);
    Response response = httpRequest.log().all().get();
    System.out.println(response.getStatusCode());
 }
}


 When I have executed the code Iam getting 400 error code while in postman 
 it is showing 200 code. Below is the console log showing the desired url is mismatch 
  Request method:   GET
  Request URI:  https://api.mathjs.org/v4/?expr=2%252F3&precision=3
   

Required Url - https://api.mathjs.org/v4/?expr=2%2F3&precision=3 Generated Url -https://api.mathjs.org/v4/?expr=2%252F3&precision=3

Don't know why the 52 is coming in query param ?expr=2%2F3 Please help on providing and explaining solution

1 Answer 1

1

Because rest-assured provides urlencode out of the box. You just need tell rest-assured "no urlencode for this one", by using .urlEncodingEnabled(false)

RequestSpecification httpRequest = RestAssured.given().relaxedHTTPSValidation().urlEncodingEnabled(false);

Result:

enter image description here

Reference: https://github.com/rest-assured/rest-assured/wiki/Usage#url-encoding

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.