接口测试用例代码
来源:互联网 发布:js判断是否出现滚动条 编辑:程序博客网 时间:2024/06/05 17:47
在设计保存个人资料代码时,我知道这是一个post请求,所有参照了主席的删除购物车的post请求,设置url和post的参数,发起请求。//设置需要请求服务器的url
String url = yxpFixture.ystoreWebAppURL+"/profile/index";List<NameValuePair> headers = new ArrayList<NameValuePair>();//设置heaserheaders.add(new BasicNameValuePair("Accept", "application/json, text/plain, */*"));headers.add(new BasicNameValuePair("Content-Type", "application/json;charset=UTF-8"));
//发起get请求获取返回HttpResponseString responseSrc = HttpRequest.get(client, url, headers);
String url = yxpFixture.ystoreWebAppURL+"/cart/delete.json";List<NameValuePair> entity = new ArrayList<NameValuePair>();// 设置entityentity.add(new BasicNameValuePair("genMyCartParamJson", "{\"cartIdAndPromoIdMap\":null,\"ordPromoId\":null,\"couponCode\":null,\"cartIdSetOfSelected\":[]}"));entity.add(new BasicNameValuePair("ids", itemId));// 提交删除请求String response = HttpRequest.post((DefaultHttpClient) client, url, entity, headers, HTTP.UTF_8);
执行后报错,返回了HTTP 415的错误( 不支持的媒体类型),估计是请求设置的参数不对。通过火狐的firebug插件分析请求的数据,哎!还真不一样,删除购物车的post参数是这样子的:String url = yxpFixture.ystoreWebAppURL+"/profile/save.json";List<NameValuePair> headers = new ArrayList<NameValuePair>();List<NameValuePair> entity = new ArrayList<NameValuePair>();// 设置entityentity.add(new BasicNameValuePair("realName", "小强"));entity.add(new BasicNameValuePair("mobile", “13575xxxx64”));
entity.add(new BasicNameValuePair("email", “test@126.com”);
......// 提交保存请求String response = HttpRequest.post((DefaultHttpClient) client, url, entity, headers, HTTP.UTF_8);
......
List<NameValuePair> headers = new ArrayList<NameValuePair>();List<NameValuePair> entity = new ArrayList<NameValuePair>();entity.add(new BasicNameValuePair("profile",jo.toString()));entity.add(new BasicNameValuePair("userProperty",jo1.toString()));String retSrc =HttpRequest.post((DefaultHttpClient)client, url, entity, headers, HTTP.UTF_8);
......
最终完成的不是很完美,都是自己摸索和学习的过程,目前开始研究购买、订单提交、组单等接口,也是慢慢摸索完成吧。......
HttpPost httpPost = new HttpPost(url);StringEntity entity = new StringEntity(obj3.toString(), HTTP.UTF_8);entity.setContentType("application/json");httpPost.setEntity(entity);HttpResponse httpResponse = client.execute(httpPost);String retSrc = EntityUtils.toString(httpResponse.getEntity());//使用EntityUtils对返回值的实体进行处理
......
- 接口测试用例代码
- 本地测试接口代码
- 软件测试-接口测试(怎样设计接口测试用例)
- 接口的客户端测试代码
- LoadRunner测试http接口代码
- Java接口测试java代码
- java post接口测试代码
- Java代码实现接口测试
- 接口测试--用例篇,如何编写app接口测试用例?
- 接口测试(二)接口测试用例设计
- 接口测试用例设计
- 接口测试用例设计
- 接口测试用例设计
- 接口测试用例小结
- 接口测试用例设计
- 接口测试用例模板
- 接口测试用例设计
- 接口测试用例设计
- linux下pm2的安装
- unity_www加载失败_IIS服务器跨域问题解决
- 深入浅出unittest
- Mybatis的mapper文件中$和#的区别
- 【POJ
- 接口测试用例代码
- 总结
- vSphere Web Client使用指南之安装配置
- Android studio中打包apk时去除debug|release
- tomcat 配置ssl
- [整理]Android三大图片加载框架Fresco,Glide,Picasso对比
- vue-cli脚手架安装
- 自定义select样式控件
- Android实现可折叠的listview