'Problem with rest assured request body parameters "value_error.missing"
I am trying to pass request body parameters in rest assured request, but it returns me with is very frustrating I am trying different ways I try with String like JSON format but is not working also always same error. Error message value_error.missing for all body parameters.
value_error.missing
{
"detail": [
{
"loc": [
"body",
"username"
],
"msg": "field required",
"type": "value_error.missing"
},
{
"loc": [
"body",
"password"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}
The test code:
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;
}
Solution 1:[1]
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()
This should work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PineappleEater |
