【发布时间】:2019-05-25 18:16:24
【问题描述】:
我正在尝试使用放心库的 RequestSpecification 或 Response 对象来读取 POST 请求正文中传递的内容。我找不到任何可以返回传递的正文内容的方法。有什么帮助吗?
public RequestSpecification Request(RequestSpecification rs)
{
rs = RestAssured.given();
if(APIConstants.BASEURL.contains("https")) {
rs = rs.relaxedHTTPSValidation();
rs.port(443);
}
return rs;
}
public RequestSpecification postRequestBuilder(RequestSpecification rs,String Body)
{
rs=Request(rs);
rs = rs.contentType(APIConstants.contentType);
if(Body!=null) {
rs = rs.body(Body);
}
return rs;
}
public Response performPOSTOperation(RequestSpecification rs,String Resource, String TestParameters)
{
Response rp=null;
String url=BASEURL+"/"+Resource+"/"+TestParameters;
System.Out.Println("Request is " +url);
rp = rs.when().post(url);
// I am trying to print Request body parameter here.
System.Out.Println("Response is " +rp.asString());
return rp;
}
public void test(){
String JSONBody="{"TestNumber":1}";
RequestSpecification rs;
rs= postRequestBuilder(rs,JSONBody);
Response rp= performPOSTOperation(rs,RESOURCE,Service);
}
我正在尝试打印在 PerformPOSTOperation() 中通过 test() 传递的 JSONBody
【问题讨论】:
标签: post request rest-assured