Search code examples
javajsonrest-assuredweb-api-testingrest-assured-jsonpath

Unable to pass raw JSON request body with response error "The browser (or proxy) sent a request that this server could not understand"


I am trying to make a GET request to the URI which has header Content-Type=application/json and has a request body which is a raw JSON type.

Below is the code I am using with RestAssured API but it throws an error in response saying "The browser (or proxy) sent a request that this server could not understand"

String Json = "{\n" +
            "    \"type\": \"estrix\",\n" +
            "    \"role_name\": \"admin\",\n" +
            "    \"id\": 001,\n" +
            "    \"start_date\": \"2018-01-01\",\n" +
            "    \"end_date\": \"2022-12-30\",\n" +
"}";
response = given().urlEncodingEnabled(true).body(Json).contentType("application/json").get(path);

Any pointers where might be the issue?


Solution

  • Had a typo of trailing comma after end_date, Corrected it below and worked.

    String Json = "{\n" +
                "    \"type\": \"estrix\",\n" +
                "    \"role_name\": \"admin\",\n" +
                "    \"id\": 001,\n" +
                "    \"start_date\": \"2018-01-01\",\n" +
                "    \"end_date\": \"2022-12-30\"\n" +
    "}";