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天了
  1. ' public Response registerDevice(String strSWAccess2,String type,String serial,String deviceId,String sig,String ctr,String nounce) throws Exception {
  2. givenWhetherNeedToLoginWithLID("yes");
  3. JSONObject body=new JSONObject();
  4. body.put("modelType",type);
  5. body.put("sn",serial);

  6. givenAnUrl(baseUrl+registerDevicePath);
  7. //用Lambda表达式,用父类中带参数的方法发Request,并拿回Response
  8. super.whenSendRequestWithMethod("post",x -> {

  9. x.cookie("SWAccess", strSWAccess).
  10. queryParam("deviceId", deviceId.trim()).
  11. queryParam("ctr", ctr.trim()).
  12. queryParam("nounce", nounce.trim()).
  13. queryParam("sig", sig.trim()).
  14. contentType("application/json").body(body).
  15. header("Cache-Control","no-cache");

  16. return x;
  17. });
  18. System.out.println("registerDevice return code:"+actualResponse.statusLine());
  19. return actualResponse;
  20. }
  21. '
  22. '
  23. public void whenSendRequestWithMethod(String httpMethod, IFunc iFunc){

  24. switch (HttpMethod.getHttpMethod(httpMethod)){
  25. case GET:
  26. actualResponse = iFunc==null?get((strURL)):iFunc.ISpecifyParams4HttpRequest(given()).get(strURL);
  27. strResponse = actualResponse.asString();
  28. break;

  29. case POST:
  30. //actualResponse = iFunc==null?given().contentType(JSON).body(strRequestBody).post(strURL):iFunc.ISpecifyParams4HttpRequest(given()).contentType(JSON).body(strRequestBody).post(strURL);
  31. actualResponse = iFunc==null?given().log().all().post(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).post(strURL);
  32. strResponse = actualResponse.asString();
  33. break;

  34. case PUT:
  35. actualResponse = iFunc==null?put(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).put(strURL);
  36. strResponse = actualResponse.asString();
  37. break;

  38. case DELETE:
  39. actualResponse = iFunc==null?delete(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).delete(strURL);
  40. strResponse = actualResponse.asString();
  41. break;

  42. default:
  43. actualResponse =iFunc==null?get(strURL): iFunc.ISpecifyParams4HttpRequest(given().log().all()).get(strURL);
  44. strResponse = actualResponse.asString();
  45. break;
  46. }

  47. logger.info("Response = " + strResponse);
  48. }
  49. '
复制代码



作者: 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