Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我们可以使用REST-Assured框架设置多个标头吗_Java_Rest_Rest Assured - Fatal编程技术网

Java 我们可以使用REST-Assured框架设置多个标头吗

Java 我们可以使用REST-Assured框架设置多个标头吗,java,rest,rest-assured,Java,Rest,Rest Assured,我有一个要求,我需要使用REST-Assured框架为REST API设置多个头 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 RequestSpecB

我有一个要求,我需要使用REST-Assured框架为REST API设置多个头

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;
}

这是我的代码,如上图所示。在这里,我们可以看到Im使用了一个私有构建头并返回了一个字符串。我将其设置为
RequestSpecBuilder
的内容类型。现在,我需要设置多个标题。有人知道怎么做吗?

你可以通过构造函数来做

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

从未使用过rest assured,但能够在javadoc中立即找到它: