51Testing软件测试论坛
标题:
Day5-5测试积点任务
[打印本页]
作者:
测试积点老人
时间:
2018-7-12 10:38
标题:
Day5-5测试积点任务
问题:
Post 请求用 postman 构造时能正常响应,相同的参数用 rest assured 请求却提示参数格式异常,哪位大神能帮忙看下?
1.如下是用postman构造的request,此api要同时传查询参数和body.postman构建请求返回为200.
[attach]117115[/attach]
2.用restassured构造相同的请求,所有 参数完全一致,甚至参数名都是直接复制的,但总是提示参数格式异常。
[attach]117116[/attach]
个人怀疑问题出在传递的body中,因为另外一条只有body请求的api也call不通,传递的body和这条内容 是一样的。这个问题困扰我2天了
' public Response registerDevice(String strSWAccess2,String type,String serial,String deviceId,String sig,String ctr,String nounce) throws Exception {
givenWhetherNeedToLoginWithLID("yes");
JSONObject body=new JSONObject();
body.put("modelType",type);
body.put("sn",serial);
givenAnUrl(baseUrl+registerDevicePath);
//用Lambda表达式,用父类中带参数的方法发Request,并拿回Response
super.whenSendRequestWithMethod("post",x -> {
x.cookie("SWAccess", strSWAccess).
queryParam("deviceId", deviceId.trim()).
queryParam("ctr", ctr.trim()).
queryParam("nounce", nounce.trim()).
queryParam("sig", sig.trim()).
contentType("application/json").body(body).
header("Cache-Control","no-cache");
return x;
});
System.out.println("registerDevice return code:"+actualResponse.statusLine());
return actualResponse;
}
'
'
public void whenSendRequestWithMethod(String httpMethod, IFunc iFunc){
switch (HttpMethod.getHttpMethod(httpMethod)){
case GET:
actualResponse = iFunc==null?get((strURL)):iFunc.ISpecifyParams4HttpRequest(given()).get(strURL);
strResponse = actualResponse.asString();
break;
case POST:
//actualResponse = iFunc==null?given().contentType(JSON).body(strRequestBody).post(strURL):iFunc.ISpecifyParams4HttpRequest(given()).contentType(JSON).body(strRequestBody).post(strURL);
actualResponse = iFunc==null?given().log().all().post(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).post(strURL);
strResponse = actualResponse.asString();
break;
case PUT:
actualResponse = iFunc==null?put(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).put(strURL);
strResponse = actualResponse.asString();
break;
case DELETE:
actualResponse = iFunc==null?delete(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).delete(strURL);
strResponse = actualResponse.asString();
break;
default:
actualResponse =iFunc==null?get(strURL): iFunc.ISpecifyParams4HttpRequest(given().log().all()).get(strURL);
strResponse = actualResponse.asString();
break;
}
logger.info("Response = " + strResponse);
}
'
复制代码
作者:
jingzizx
时间:
2018-7-13 10:11
报文头是否有差别?
作者:
abcsell
时间:
2018-7-13 10:34
应该是报文头之间的问题
作者:
qqq911
时间:
2018-7-13 11:00
看下报文头里面的session 等信息
作者:
104~牛牛
时间:
2018-7-13 14:04
看不懂,posman没用过呢
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2