使用带参数的帖子请求时出现以下错误:
{
"failure":{
"failureCode":"1035",
"failureDetails":"Id: null format is not valid",
"failureInstance":null,
"failureMessage":"Malformed ID(s) detected.",
"failureMessageParameter":null
}
}
以下是我的代码:
LoadProperties lp = new LoadProperties();
@BeforeTest
public void beforeTest(){
lp.load();
RestAssured.keyStore(lp.getProperty("certificatePath"),lp.getProperty("certificatePassword"));
RestAssured.trustStore(lp.getProperty("cacertsPath"), lp.getProperty("cacertsPassword"));
}
@Test
public void test(){
RestAssured.baseURI = lp.getProperty("baseURL");
RequestSpecification request = RestAssured.given().header("Authorization", lp.getProperty("AccessToken"));
request.header("Content-Type","application/json");
JSONObject json = new JSONObject();
try{//**Here I add parameters to json object**
json.put("", lp.getProperty(""));
json.put("", lp.getProperty(""));
json.put("", lp.getProperty(""));
json.put("", lp.getProperty(""));
json.put("", lp.getProperty(""));
json.put("", lp.getProperty(""));
json.put("", lp.getProperty(""));
}catch(Exception e){
e.printStackTrace();
}
request.body(json.toString());
Response response = request.post(lp.getProperty("URL"));
String statusCode = String.valueOf(response.statusCode());
System.out.println(response.body().asString());
Assert.assertEquals(statusCode, "200");
}
但是,如果我使用硬编码数据(String sData =“{Parameters}”)传递给请求体,我会得到所需的结果,但在使用json对象时却没有。我也尝试过使用GSON将json对象转换为jsonString,但仍然与上面的响应相同。
请帮忙。 感谢。