在Rest-Assured中重新设置标题/内容类型

问题描述 投票:0回答:1

我是新来的 - 确保我正在上传文件,然后做一个获取请求来查看内容。对于上传,content-type是multipart / form-data,我使用以下代码来设置值this.setRequest(RestAssured.given().accept("application/json")); this.setRequest(RestAssured.given().contentType("multipart/form-data")); this.setRequest(RestAssured.given().header("authorization", ConfigHelper.getString(user)));

对于检索内容,我再次将值重新设置为以下代码。 this.setRequest(RestAssured.given().contentType("application/json")); this.setRequest(RestAssured.given().header("authorization", ConfigHelper.getString(user))); this.setRequest(RestAssured.given().accept("application/json"));

但是当我尝试执行上传时,我收到错误为“

请求Content-Type不是multipart / form-data

"

我不确定,我在这里做错了什么,最初当它只上传它工作正常但是当我添加到GET内容时,我收到这些错误。

automation rest-assured web-api-testing
1个回答
0
投票

使用[rest-assured]是链接api。在上面的代码中,每次创建新的请求规范而不是更新现有的规范。

使用代码如下

RequestSpecification request = given()
            .accept("application/json")
            .contentType("multipart/form-data")
            .header("authorization", ConfigHelper.getString(user));
© www.soinside.com 2019 - 2024. All rights reserved.