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请求测试代码的更多相关文章

  1. 在内核中异步请求设备固件firmware的测试代码

    在内核中异步请求设备固件firmware的测试代码 static void ghost_load_firmware_callback(const struct firmware *fw, void * ...

  2. 在Jmeter中使用自定义编写的Java测试代码

    我们在做性能测试时,有时需要自己编写测试脚本,很多测试工具都支持自定义编写测试脚本,比如LoadRunner就有很多自定义脚本的协议,比如"C Vuser","Java ...

  3. 利用python httplib模块 发送Post请求测试web服务是否正常起来!

    最近在学习python,恰好老大最近让我搞个基于post请求测试web服务是否正常启用的小监控,上网查了下资料,发现强大的Python恰好能够用上,所以自己现学现卖,顺便锻炼下自己. 由于本人也刚接触 ...

  4. 全--教程API, gem 'rest-client'(用于发简单请求); 请求测试;

    安装:rest-client4400✨ gem install rest-client 一个简单的HTTP和REST client for Ruby. 可以用它来发HTTP请求 基本用法: requi ...

  5. 自定义编写jmeter的Java测试代码

    我们在做性能测试时,有时需要自己编写测试脚本,很多测试工具都支持自定义编写测试脚本,比如LoadRunner就有很多自定义脚本的协议,比如"C Vuser","JavaV ...

  6. Java&Selenium自动化测试实现页面元素、页面对象及测试代码分离

    一.摘要 本篇博文将介绍自动化测试实现页面元素.页面对象及测试代码分离在自动化框架中的实现 二.解析页面元素定位信息 首先,将页面元素与实际的代码分离,首先我们将页面元素定位信息和定位表达式保存在属性 ...

  7. 使用 TypeScript & mocha & chai 写测试代码实战(17 个视频)

    使用 TypeScript & mocha & chai 写测试代码实战(17 个视频) 使用 TypeScript & mocha & chai 写测试代码实战 #1 ...

  8. .NET单元测试的艺术-3.测试代码

    开篇:上一篇我们学习单元测试和核心技术:存根.模拟对象和隔离框架,它们是我们进行高质量单元测试的技术基础.本篇会集中在管理和组织单元测试的技术,以及如何确保在真实项目中进行高质量的单元测试. 系列目录 ...

  9. mysql锁 实战测试代码

    存储引擎 支持的锁定 MyISAM 表级锁 MEMORY 表级锁 InnoDB 行级锁 BDB 页面锁 表级锁:开销小,加锁快:不会出现死锁:锁定粒度大,发生锁冲突的概率最高,并发度最低.行级锁:开销 ...

随机推荐

  1. Linux 环境变量问题

    环境变量延伸: /etc/profile, /etc/bashrc, .bash_profile和.bashrc的差别 用户在登陆Linux操作系统的时候,"/etc/profile&quo ...

  2. 第16月第31天 mongo

    1. 94  brew install  mongodb 95  cd ~ 96  cd Desktop/web/ 97  ls 98  mkdir mongo 99  cd mongo/ 100  ...

  3. 设置PHPStorm 注释

    /** * Desc: xxx#if (${NAME}) * Class: ${NAME}#end#if (${NAMESPACE}) * Package: ${NAMESPACE}#end * Us ...

  4. php rsa理解

    参考链接:http://www.cnblogs.com/firstForEver/p/5803940.html 自己封装的一个类: <?php class CRsaAuthorization { ...

  5. SSM框架中将时间写入数据库的格式定义

    //声明Date类接收的数据格式 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private Date addtime;

  6. 终端命令行开启和关闭mac隐藏文件

    defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write com.apple.finde ...

  7. android 面试题(一)

    1.Android中真实宽高,getWidth和getMeasuredWidth的区别:哪个计算的是真实的宽? getWidth():得到的是View在父Layout中布局好后的宽度值,如果没有父布局 ...

  8. JDK7与8内存参数解析与修改

    JDK内存 jdk内存实际是jvm内存,jvm有一个运行时数据区,其实就是对这一部分的大小分配. 运行时数据区通常包括这几个部分:程序计数器(Program Counter Register).Jav ...

  9. springboot系列十、springboot整合redis、多redis数据源配置

    一.简介 Redis 的数据库的整合在 java 里面提供的官方工具包:jedis,所以即便你现在使用的是 SpringBoot,那么也继续使用此开发包. 二.redidTemplate操作 在 Sp ...

  10. Python3学习笔记10-条件控制

    Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块 var1 = 100 if var1: print("1 - if 表达式条件为 true&q ...