我试图在放心的请求中传递请求体参数,但它返回给我是非常令人沮丧的,我正在尝试不同的方式,我尝试像JSON格式的字符串,但不工作也总是相同的错误。错误信息value_error.missing
value_error.missing
{
"detail": [
{
"loc": [
"body",
"username"
],
"msg": "field required",
"type": "value_error.missing"
},
{
"loc": [
"body",
"password"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}
测试代码:
public Response login(String username, String password, String proxy) {
//String user = "{"username":"" + username + "","password":"" + password + "","proxy":"" + proxy + ""}";
Map<String, String> user = new HashMap<>();
user.put("username", username);
user.put("password", password);
user.put("proxy", proxy);
Response response = given()
.headers(httpHeaderManager())
.body(user)
.spec(urlUser)
.post("/auth/login")
.then()
.extract().response()
return response;
}
JSONObject jsonObj = new JSONObject();
jsonObj.put("username", username);
jsonObj.put("password", password);
jsonObj.put("proxy", proxy);
RequestBody body = RequestBody.create(jsonObj.toString(), MediaType.parse("application/json; charset=utf-8"));
Response response = given()
.headers(httpHeaderManager())
.body(body)
.spec(urlUser)
.post("/auth/login")
.then()
.extract().response()
应该可以