setting content type in rest assured

后端 未结 8 1270
广开言路
广开言路 2021-01-07 21:53

I\'m trying to invoke a rest call using rest assured. My API accepts, \"application/json\" as content type and I need to set in the call. I set the content type

8条回答
  •  天命终不由人
    2021-01-07 22:44

    Here is the complete POST example using CONTENT_TYPE as JSON.

    import io.restassured.http.ContentType;
    
    RequestSpecification request=new RequestSpecBuilder().build();
    ResponseSpecification response=new ResponseSpecBuilder().build();
    @Test
    public void test(){
       User user=new User();
       given()
        .spec(request)
        .contentType(ContentType.JSON)
        .body(user)
        .post(API_ENDPOINT)
        .then()
        .statusCode(200).log().all();
    }
    

提交回复
热议问题