`

HttpClient

    博客分类:
  • JAVA
 
阅读更多
package com.nos.java.action;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;

public class 参考HttpSmsUtil {
public static void main(String[] args) {

// System.out.println(new MD5().getMD5ofStr("kouyan12345").toLowerCase());
// testGetClient();
// senSmsTest();
/* testPool(); */

/* for(int i=0; i<5000; i++) {
new Thread(new Test()).start();
}*/
/* testYsy();
LoggerUtil.debug("****************************", "*******************************************");*/
// System.out.println(MD5Util.md5Hex("123456"));
// HttpSmsUtil.senSmsTest();
// HttpSmsUtil.testGetInvitedMeets();
// HttpSmsUtil.testHandShake();
// HttpSmsUtil.testYsyHandShake();
// HttpSmsUtil.testGetMobileKey();
// HttpSmsUtil.testRegCompMem();
// HttpSmsUtil.testfe();
}

public static void testPool() {
try {
HttpClient client = new HttpClient();//定义client对象 
    client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
    client.getHttpConnectionManager().getParams().setConnectionTimeout(3000);//设置连接超时时间为2秒(连接初始化时间) 
    PostMethod method = new PostMethod("http://10.0.7.20/linkjm.action?cid=86243850&codeid=bcqpy");
//     http://192.168.10.14:8080/wms/backPlant/mobileLogin/mGetgoodsList.action
    int statusCode = client.executeMethod(method); 
    if (statusCode != HttpStatus.SC_OK) { 
       System.out.println("远程访问失败。"); 
    } 
System.out.println(method.getResponseBodyAsString());//输出反馈结果 
}catch(Exception e) {
e.printStackTrace();
}
}

// public static void senSmsTest() {
// try { 
//     HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://119.145.9.12/sendSMS.action"); 
//     method.setRequestBody(new NameValuePair[] { 
//                   new NameValuePair("enterpriseID" , "15591"),
//                   new NameValuePair("loginName" , "admin"),
//                   new NameValuePair("password" , MD5Util.md5Hex("kouyan12345").toLowerCase()),
//                   new NameValuePair("smsId" , ""),
//                   new NameValuePair("subPort" , "01"),
//                   new NameValuePair("content" , "hello sms!!"),
//                   new NameValuePair("mobiles" , "13725571493"),
//                   new NameValuePair("sendTime" , "")
//     }); 
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
//     System.out.println(method.getResponseBodyAsString());//输出反馈结果 
//     client.getHttpConnectionManager().closeIdleConnections(1); 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testGetClient() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://10.0.7.20/servlet/getClientAccKey");
//     String sb = "CRMT:LU1FRVRVUkw9MTAuMC43LjIwL3NlcnZsZXQvZ2V0Q2xpZW50QWNjS2V5Ci1NRUVUPTg2MjQzODUwOzgwMjA0YTA2MmMyYmFhOTM1MDYxNDY5ZWNiZDIyYjQxO0NMT1VEUk9PTQotQUNOVD0wOzQ7MDg4OGQ2MWI1MTRjMzFjZTI4ZDRhZjg2NWRmNzg5MzU7NjE2YzcwNjg2MTsKLUxBTkc9emhfQ04KLU1FRVRUWVBFPU1BSU4KLUxPR0NGRz0wCi1XRUJTVlI9MTAuMC43LjIwOzEwLjAuNy4yMDsxMC4wLjcuMjA=";
// /*   InputStream body = new ByteArrayInputStream(sb.getBytes());
//     method.setRequestBody(body);*/
//     StringRequestEntity  entity = new StringRequestEntity(sb,null,"UTF-8");
//     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// // System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
// //http://10.0.7.20/link_start.action?codeid=bcqmq&cid=27092130&retry=0&nickname=agent1
// public static void testJoinLink() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://10.0.7.20/link_start.action?codeid=bcqpy&cid=86243850&retry=0&nickname=alpha");
// //     String sb = "CRMT:LU1FRVRVUkw9MTAuMC43LjIwL3NlcnZsZXQvZ2V0Q2xpZW50QWNjS2V5Ci1NRUVUPTQwNDMxMjE5OzlkODE3ZGIxMGRjN2EyNTJlODhhMzk5OTFmOThlNmZmO0NMT1VEUk9PTQotQUNOVD0xMDAwMDAwMDM2OzE7NzU5YTRiZjAwYWRmZDA1NjQ5YjdlNjBjMTIyNjFlY2E7NjE2YzcwNjg2MTsKLUxBTkc9emhfQ04KLU1FRVRUWVBFPU1BSU4KLUxPR0NGRz0wCi1XRUJTVlI9MTAuMC43LjIwOzEwLjAuNy4yMDsxMC4xMS4xMi4xMzsxMC4wLjcuMjA=";
// /*   InputStream body = new ByteArrayInputStream(sb.getBytes());
//     method.setRequestBody(body);*/
// //     StringRequestEntity  entity = new StringRequestEntity(sb,null,"UTF-8");
// //     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testYsy() {
//
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://127.0.0.1/si/auth/notice?streamingno=13221345&rand=2525&encode=3231");
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testImgSrc() {
//
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://localhost/news/81.html");
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
//
// List<String> rest = getImgStr(method.getResponseBodyAsString());
// for(String rs : rest) {
// System.out.println("rs:"+rs);
// }
//
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static List<String> getImgStr(String htmlStr){  
//        String img="";  
//        Pattern p_image;  
//        Matcher m_image;  
//        List<String> pics = new ArrayList<String>();
//
//   //     String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址 
//
//          String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
//        p_image = Pattern.compile
//                (regEx_img,Pattern.CASE_INSENSITIVE);  
//       m_image = p_image.matcher(htmlStr);
//       while(m_image.find()){  
//            img = img + "," + m_image.group();  
//           // Matcher m  = Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(img); //匹配src
//
//           Matcher m  = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
//
//            while(m.find()){
//                pics.add(m.group(1));
//            }
//        }  
//           return pics;  
//    } 
//
//
// public static void testGetInvitedMeets() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://10.0.0.136/servlet/GetInvitedMeets");
//   /*  method.setRequestBody(new NameValuePair[] { 
//                   new NameValuePair("{RequestId" , "15591ss"),
//                   new NameValuePair("OEMKey" , "CLOUDROOM"),
//                   new NameValuePair("UserPswd" , new MD5().getMD5ofStr("123456").toLowerCase()),
//                   new NameValuePair("ClientVer" , "1.2.0"),
//                   new NameValuePair("UserName" , "alpha@alpha.com}")
//     });  */
//     String sb = "{\"RequestId\":\"15591ss\",\"OEMKey\":\"CLOUDROOM\",\"UserPswd\":\""+MD5Util.md5Hex("123456").toLowerCase()+"\",\"ClientVer\":\"1.2.0\",\"UserName\":\"3261750121\"}";
// /*   InputStream body = new ByteArrayInputStream(sb.getBytes());
//     method.setRequestBody(body);*/
//     StringRequestEntity  entity = new StringRequestEntity(sb,null,"UTF-8");
//     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testHandShake() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://10.0.7.20/servlet/HandShake");
//   /*  method.setRequestBody(new NameValuePair[] { 
//                   new NameValuePair("{RequestId" , "15591ss"),
//                   new NameValuePair("OEMKey" , "CLOUDROOM"),
//                   new NameValuePair("UserPswd" , new MD5().getMD5ofStr("123456").toLowerCase()),
//                   new NameValuePair("ClientVer" , "1.2.0"),
//                   new NameValuePair("UserName" , "alpha@alpha.com}")
//     });  */
//     String sb = "{\"RequestId\":\"15591ss\",\"OEMKey\":\"CLOUDROOM\",\"UserPswd\":\""+MD5Util.md5Hex("123456").toLowerCase()+"\",\"ClientVer\":\"1.2.0\",\"UserName\":\"3261750121\",\"MeetID\":\"12345678\",\"Status\":\"2\"}";
// /*   InputStream body = new ByteArrayInputStream(sb.getBytes());
//     method.setRequestBody(body);*/
//     StringRequestEntity  entity = new StringRequestEntity(sb,null,"UTF-8");
//     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
//
// public static void testYsyHandShake() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://www.189esy.cn:8080/FS-ECD-CLIENT/loginForPhone");
//   /*  method.setRequestBody(new NameValuePair[] { 
//                   new NameValuePair("{RequestId" , "15591ss"),
//                   new NameValuePair("OEMKey" , "CLOUDROOM"),
//                   new NameValuePair("UserPswd" , new MD5().getMD5ofStr("123456").toLowerCase()),
//                   new NameValuePair("ClientVer" , "1.2.0"),
//                   new NameValuePair("UserName" , "alpha@alpha.com}")
//     });  */
//     long epoch = System.currentTimeMillis()/1000;
//     String sb = "{\"userid\":\"18906917784\",\"password\":\"654321a\",\"encrypted\":\"0\",\"imei\":\"359652053048984\",\"appid\":\"140002350000000000000011\",\"timestamp\":\""+epoch+"\",\"authenticator\":\""+MD5Util.ysymd5("18906917784"+"654321a"+"359652053048984"+"140002350000000000000011"+epoch+"5029C3055D51")+"\"}";
// // String sb = "{userid:'master@1163688247',password:'n3P//IKYRk1Q7TzGDZqp3g==',encrypted:'1',imei:'359652053048984',appid:'140002350000000000000011',timestamp:'1414999077',authenticator:'LHlgdJhqKiyrVrhJA/RLxA=='}";
//     /*   InputStream body = new ByteArrayInputStream(sb.getBytes());
//     method.setRequestBody(body);*/
//     StringRequestEntity  entity = new StringRequestEntity(sb,"application/json","UTF-8");
//     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testGetMobileKey() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://127.0.0.1/appws/app/register/getSmsKey");
//    
//     String sb = "{\"RequestId\":\"15591ss\",\"mobile\":\"13725571493\"}";
//     StringRequestEntity  entity = new StringRequestEntity(sb,"application/json","UTF-8");
//    
//     method.setRequestEntity(entity);
//    
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testRegCompMem() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://127.0.0.1/appws/app/register/regmem");
//     String sb = "{\"RequestId\":\"cccccccccc13213\",\"mobile\":\"13725571493\",\"compMobile\":\"17790090601\",\"identifyCode\":\"960925\"}";
//     StringRequestEntity  entity = new StringRequestEntity(sb,"application/json","UTF-8");
//     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
// public static void testfe() {
// try {
// HttpClient client = new HttpClient();//定义client对象 
//     client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");//指定传送字符集为GBK格式 
//     client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//设置连接超时时间为2秒(连接初始化时间) 
//     PostMethod method = new PostMethod("http://10.2.11.123/appws/app/cmpuser/adduser");
//     String sb = "{\"RequestId\":\"cccccccccc13213\",\"mobile\":\"13725571493\",\"compMobile\":\"17790090601\",\"identifyCode\":\"960925\"}";
//     StringRequestEntity  entity = new StringRequestEntity(sb,"application/json","UTF-8");
//     method.setRequestEntity(entity);
//     int statusCode = client.executeMethod(method); 
//     if (statusCode != HttpStatus.SC_OK) { 
//        System.out.println("远程访问失败。"); 
//     } 
// System.out.println(method.getResponseBodyAsString());//输出反馈结果 
// }catch(Exception e) {
// e.printStackTrace();
// }
// }
//
//}

class Test implements Runnable{

public void run() {
参考HttpSmsUtil.testPool();
// HttpSmsUtil.testGetClient();
// HttpSmsUtil.testJoinLink();
}

}
}
分享到:
评论

相关推荐

    httpclient.jar包下载

    《深入解析httpclient.jar及其与code.jar的关联》 在Java开发中,HTTP通信是不可或缺的一部分,而Apache HttpClient库正是Java实现HTTP客户端操作的重要工具。本文将深入探讨httpclient.jar包,以及它与code.jar包...

    httpclient官网教程中文版

    ### Httpclient官网教程中文版知识点总结 #### 一、引言 HTTP协议作为互联网的核心通信标准之一,在现代网络服务及物联网设备中扮演着至关重要的角色。随着技术的发展,越来越多的应用和服务依赖于HTTP协议来实现...

    HttpClient4.2.1版本的Jar包

    HttpClient 4.2.1版本引入了一些重要的改进和修复,以提高性能和稳定性。以下是一些关键特性: 1. **连接管理**:HttpClient 4.2.1引入了更完善的连接管理机制,允许开发者控制连接的创建、复用和关闭。`...

    HttpClient 3.x to HttpComponents HttpClient 4.x

    例如,在HttpClient 3.x中,代码可能会使用`***mons.httpclient.HttpClient`类和`***mons.httpclient.methods.GetMethod`等,而在4.x版本中,这些都被新的API所替代。程序员需要熟悉`org.apache....

    httpclient-4.2.5-API文档-中文版.zip

    赠送jar包:httpclient-4.2.5.jar; 赠送原API文档:httpclient-4.2.5-javadoc.jar; 赠送源代码:httpclient-4.2.5-sources.jar; 赠送Maven依赖信息文件:httpclient-4.2.5.pom; 包含翻译后的API文档:httpclient...

    httpclient4.2.1.zip

    本文将深入探讨HttpClient 4.2.1的核心特性和使用方法,帮助开发者更好地理解和应用这个强大的工具。 一、HttpClient简介 HttpClient是一个开放源码的Java库,由Apache软件基金会维护。它为Java程序员提供了一个...

Global site tag (gtag.js) - Google Analytics