我正在使用 RestAssured 发送请求:
Map<String, Object> headers = new HashMap<>();
headers.put("Accept", "*/*");
headers.put("Accept-Encoding", "gzip, deflate, br");
headers.put("Connection", "keep-alive");
Response response = RestAssured.given().baseUri(BASE_URL)
.headers(headers)
.log().all()
.post(URL_PREFIX + "/documents/request/" + username);
但是,在日志中,我看到自动添加了另外 1 个标题:
Content-Type=application/x-www-form-urlencoded; charset=ISO-8859-1
我收到 415 错误。 是否可以在没有 Content-Type 的情况下发送请求?我的意思是,根本没有这个标题;如果请求发送的 Content-Type 等于空行,仍然有 400 错误;使其工作的唯一方法是发送没有此标头的请求。
答案 0 :(得分:0)
RestAssured 框架中似乎有一个 bug 仍然开放(我在 4.3.3 中验证过)。
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
testImplementation group: 'io.rest-assured', name: 'rest-assured', version: '4.3.3'
在为 API 创建负面测试时发现。尝试发送请求时会自动生成以下内容类型。
Content-Type=application/x-www-form-urlencoded; charset=ISO-8859-1
此处定义的错误: