Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to send file in request body rest assured

 public void sentFileInRequestBody() {

        //insert the file path you try to send in req body form-data
        File file = new File("");

        //base url 
        RestAssured.baseURI = "";
        
        RequestSpecification httpRequest = RestAssured.given()
                //insert query params
                .queryParam("key", "value")
                //insert headers
                .header("key", "value")

                //if you send files in request body -> form-data, use this
                .contentType("multipart/form-data")
                .multiPart("key", file);

        //Http request with base path
        Response response = httpRequest.request(Method.POST, "/your path");

        //print response
        String responseBody = response.getBody().asPrettyString();
        System.out.println(responseBody);
    }
 
PREVIOUS NEXT
Tagged: #send #file #request #body #rest #assured
ADD COMMENT
Topic
Name
9+2 =