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 页面锁 表级锁:开销小,加锁快:不会出现死锁:锁定粒度大,发生锁冲突的概率最高,并发度最低.行级锁:开销 ...
随机推荐
- VS2017的安装和配置
VS2017专业版安装文件下载:链接:https://pan.baidu.com/s/1tJRYdj_9LzvTSDF5TkkMRg 提取码:tgh5 一些窗口:菜单栏--->视图 字 ...
- mysql 案例~关于pt-osc工具的用途
简介:今天咱们聊聊PT-OSC的东东一 简单介绍 1 标准组合 pt-online-schema-change --user= --password= --host= D=,t= --sock= ...
- Django学习手册 - 自定义simple_tag / filter
相关: Django的模板引擎提供一般性的功能函数,通过前端可以实现多数的代码逻辑功能,但它仅支持大多数常见情况下的函数功能,例如if判断,ifequal对比返回值等,复杂一些的函数功能并不支持,例如 ...
- Android ThreadPool
在Android开发中,如果我们要执行某个耗时任务,一般都会考虑开启一个线程去处理. 一个线程run方法执行完毕后,才算真正结束:但是,这只是结束,并没有被回收:会一直闲置在那里,等待GC去回收.所以 ...
- 判断网络远端服务器是否断开连接(心跳连接:socket.sendUrgentData)
1.socket类的方法isClosed().isConnected().isInputStreamShutdown().isOutputStreamShutdown()等,这些方法都是本地端的状态, ...
- js中,for循环里面放ajax,ajax访问不到变量以及每次循环获取不到数据问题总结
想在点击"终端控制"的时候能够开启多个窗口对多个终端进行管理: /**提交事件**/ $("#terminalControl").bind("clic ...
- SVM实例及Matlab代码
******************************************************** ***数据集下载地址 :http://pan.baidu.com/s/1geb8CQf ...
- jvm系列五、jvm垃圾回收机制、jvm各种参数及调优
转载自:http://yufenfei.iteye.com/blog/1746914 尊重原创. 一.GC有两种类型:Scavenge GC 和Full GC 1.Scavenge GC 一般情况下, ...
- 转载:《理解RESTful架构》 阮一峰
原文:http://www.ruanyifeng.com/blog/2011/09/restful.html 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件&q ...
- jQuery性能优化指南
总是从ID选择器开始继承在jQuery中最快的选择器是ID选择器,因为它直接来自于JavaScript的getElementById()方法. 例如有一段HTML代码:代码 <div id=&q ...