简体   繁体   中英

Can we set more than one header using REST-Assured framework

I've a requirement that i need to set more than one header for a REST API using REST-Assured framework.

private static String buildHeader(){
    String header = "application/json; charset=UTF-8";
    return header;
}
/** This method is used to build a body for request specification**/
private static RequestSpecBuilder buildBody(JSONObject json) throws ConfigurationException, URISyntaxException, IOException{
    //JSONObject json = JsonData.getPostJSONData();
    String APIBody = json.toString();
    RequestSpecBuilder resBuilder = new RequestSpecBuilder();
    resBuilder.setBody(APIBody);
    resBuilder.setContentType(RequestBuilder.buildHeader());
    return resBuilder;
}

This is my code which is shown above. In this we can see that Im using a private build header and just returned a string. I set it as a content type to RequestSpecBuilder . So now, I've requirement that I need to set more than one header. Does anybody know how to do that?

You can do it through the constructor

RequestSpecification resBuilder= new RequestSpecBuilder()
                    .setContentType(ContentType.JSON)
                    .addHeader("Auth", "my-auth")
                    .addHeader("X-API-Version", apiVersion))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM