post请求测试代码
public class TestResourceCommentRestController {
private final static String API_URI_DEBUG = "http://localhost:8080/wodm-api/api/v1";
public static final int HASH_INTERATIONS = 1024;
private static boolean FLAG_DEBUG = true;
public static void main(String[] args) {
testComment();
// System.out.println("makeAppkey="+Strings.makeAppkey());
// makeAppkey();
// String[] chars = null;
// chars = Lists.newArrayList("").toArray(chars);
// for (int i = 0; i < 10; i++) {
// System.out.println("["+i+"]"+RandomStringUtils.random(32, "abcdefghijklmnopqrstuvwlyz0123456789"));
// }
}
public static void makeAppkey(){
System.out.println(RandomStringUtils.random(32, "abcdefghijklmnopqrstuvwlyz0123456789"));
}
public static void testComment(){
String httpUrl = null;
if(FLAG_DEBUG){
httpUrl = API_URI_DEBUG + "/comment/reply";
}else { httpUrl = API_URI + "/comment"; }
String postBody = null;
//ResourceCommentDTO1 dto = new ResourceCommentDTO1();
JSONObject object=new JSONObject();
for(long i = 584 ;i < 585 ; i++){
object.put("sendId", 449L);
object.put("content", "回复222222!");
object.put("receiveId", 457l);
object.put("parentId", 1877l);
object.put("commentId", 1877l);
object.put("type", 1);
object.put("resourceId",i);
/*dto.setResourceId(i);
dto.setSendId(147L);
dto.setContent("回复222222!");
dto.setParentId(322l);*/
//List<Long> list=new ArrayList<Long>();
/*list.add(143l);
list.add(438l);*/
//dto.setReceiveIds(list);
//object.put("receiveIds", list);
postBody = JSON.toJSONString(object);
//postBody = JSON.toJSONString(dto);
System.out.println("---"+postBody);
String respBody = httpPost(httpUrl, postBody);
System.out.println("respBody="+respBody);
}
}
private static String httpPost(String httpUrl, String body) {
URL remoteUrl = null;
OutputStreamWriter wr = null;
InputStream is = null;
BufferedReader reader = null;
try {
URLConnection conn = null;
remoteUrl = new URL(httpUrl);
conn = remoteUrl.openConnection();
conn.setDoOutput(true);
conn.setConnectTimeout(5 * 1000);// time out 5s
conn.setRequestProperty("Content-Type", "application/json");
// conn.setRequestProperty("Accept",
// "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
//
// conn.setRequestProperty("Accept",
// "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
// conn.setRequestProperty("Accept-Language", "en-us,en;q=0.5");
// conn.setRequestProperty("Connection", "keep-alive");
// conn.setRequestProperty(
// "User-Agent",
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:13.0) Gecko/20100101 Firefox/13.0.1");
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(body);
wr.flush();
is = conn.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
// response
StringBuffer responseBody = new StringBuffer();
String responseStr = null;
while ((responseStr = reader.readLine()) != null) {
if (responseBody.length() > 0) {
responseBody.append("\r\n");
}
responseBody.append(responseStr);
}
return responseBody.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
post请求测试代码的更多相关文章
- 在内核中异步请求设备固件firmware的测试代码
在内核中异步请求设备固件firmware的测试代码 static void ghost_load_firmware_callback(const struct firmware *fw, void * ...
- 在Jmeter中使用自定义编写的Java测试代码
我们在做性能测试时,有时需要自己编写测试脚本,很多测试工具都支持自定义编写测试脚本,比如LoadRunner就有很多自定义脚本的协议,比如"C Vuser","Java ...
- 利用python httplib模块 发送Post请求测试web服务是否正常起来!
最近在学习python,恰好老大最近让我搞个基于post请求测试web服务是否正常启用的小监控,上网查了下资料,发现强大的Python恰好能够用上,所以自己现学现卖,顺便锻炼下自己. 由于本人也刚接触 ...
- 全--教程API, gem 'rest-client'(用于发简单请求); 请求测试;
安装:rest-client4400✨ gem install rest-client 一个简单的HTTP和REST client for Ruby. 可以用它来发HTTP请求 基本用法: requi ...
- 自定义编写jmeter的Java测试代码
我们在做性能测试时,有时需要自己编写测试脚本,很多测试工具都支持自定义编写测试脚本,比如LoadRunner就有很多自定义脚本的协议,比如"C Vuser","JavaV ...
- Java&Selenium自动化测试实现页面元素、页面对象及测试代码分离
一.摘要 本篇博文将介绍自动化测试实现页面元素.页面对象及测试代码分离在自动化框架中的实现 二.解析页面元素定位信息 首先,将页面元素与实际的代码分离,首先我们将页面元素定位信息和定位表达式保存在属性 ...
- 使用 TypeScript & mocha & chai 写测试代码实战(17 个视频)
使用 TypeScript & mocha & chai 写测试代码实战(17 个视频) 使用 TypeScript & mocha & chai 写测试代码实战 #1 ...
- .NET单元测试的艺术-3.测试代码
开篇:上一篇我们学习单元测试和核心技术:存根.模拟对象和隔离框架,它们是我们进行高质量单元测试的技术基础.本篇会集中在管理和组织单元测试的技术,以及如何确保在真实项目中进行高质量的单元测试. 系列目录 ...
- mysql锁 实战测试代码
存储引擎 支持的锁定 MyISAM 表级锁 MEMORY 表级锁 InnoDB 行级锁 BDB 页面锁 表级锁:开销小,加锁快:不会出现死锁:锁定粒度大,发生锁冲突的概率最高,并发度最低.行级锁:开销 ...
随机推荐
- luogu P2325 [SCOI2005]王室联邦
传送门 做法是dfs整棵树,当访问一个点\(x\)时,先访问儿子,若某个时刻子树大小\(\ge b\)时,就把那些点放在一个省里,省会记为\(x\),访问完儿子再把\(x\)加入栈.最后栈中剩余的没加 ...
- http raw post 之理解
参考链接: https://imququ.com/post/four-ways-to-post-data-in-http.html http://blog.csdn.net/leyangjun/art ...
- mysql 案例 ~ pt-io工具的使用
一 简介:如何使用pt-iopfile调查io具体信息二 目的:利用pt-iopfile分析mysql内部IO操作密集的文件,用以发现问题三 使用: pt-iopfile -p mysql_pid ...
- UML和模式应用4:初始阶段(1)--概述
1.前言 UP开发包括四个阶段:初始阶段.细化阶段.构建阶段.移交阶段: 初始阶段是项目比较简短的起始步骤,主要目的是收集足够的信息来建立共同设想,调查项目的总体目标和可行性,确定是否值得进一步深入. ...
- unicode 和 utf-8字符编码的区别
作者:于洋链接:https://www.zhihu.com/question/23374078/answer/69732605来源:知乎著作权归作者所有,转载请联系作者获得授权. 原文:unico ...
- P3567 [POI2014]KUR-Couriers
题目描述 Byteasar works for the BAJ company, which sells computer games. The BAJ company cooperates with ...
- gulp-px2rem-plugin 插件的一个小bug
最近在使用这个插件的过程中发现一个bug: 不支持 含有小数的形式. 查看源码后,修改了下其中的正则,使其支持小数形式(66.66px..6px ). 作者的源码最近一次更新都在两年前,所以就简单的记 ...
- 前端工程化-webpack(打包JS)(二)
一.第一种打包方式 webpack entry<entry> output 假设目录结构如下: index.html是入口文件 打包app.js为bundle.js如下 app.js 当使 ...
- vue之导入Bootstrap以及jQuery的两种方式
Vue引入bootstrap主要有两种方法 方法一:在main.js中引入,此方法导入的bootstrap中对于html,body的一些预设置的css样式可能无效. 一.引入jQuery 在当前项目的 ...
- python接口自动化测试十二:对返回的json的简单操作
# 1.requests里面自带解析器转字典 print(r.json()) print(type(r.json())) # 取出json中的'result_sk_temp'字段 # {"r ...