- 浏览: 100943 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (209)
- http://docs.jpush.io/server/java_sdk/ (1)
- SpingMVC ModelAndView (1)
- Model (1)
- Control以及参数传递 (1)
- https://www.alipay.com/ (1)
- 检查指定的字符串列表是否不为空。 (1)
- 转自http://my.oschina.net/rpgmakervx/blog/505434 (1)
- 压缩js (1)
- 含包含 字母数字校验 (1)
- 判断浏览器是ie (1)
- fixbox (0)
- 转自http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html (1)
- http://dl2.iteye.com/upload/attachment/0113/2406/afbd8d53-dcad-3afc-8d78-41c1591 (0)
- IDEA (0)
- maven搭建 (0)
- http://www.jeasyuicn.com/api/docTtml/index.htm (1)
- 给tomcat添加运行内存: (1)
- JPUSH推送 (1)
- requestScope (0)
- oracle中plsql安装client10连接数据库 (1)
- 不需要安装oracle11g (1)
- tuikuan (1)
- http://www.hjxmall.com/index.php (1)
- java (1)
- 参考 (1)
- xml签名验签模拟程序 (1)
- 技术网站收集分享 (1)
- Java NIO提供了与标准IO不同的IO工作方式 ------来源于 http://www.iteye.com/magazines/132-Java-NIO (1)
- oracle表查询语句优化 (0)
- oracle (5)
- a (1)
- TenpayHttpClient (2)
- mongodb (1)
- http://www.qcloud.com/product/cmongo.html?utm_source=pcsem1&utm_medium=bdgj46&utm_campaign=baidu (1)
- SpringMVC整合MongoDB开发 (0)
- SpringMVC整合MongoDB开发 https://www.mongodb.org (1)
- Java 语言中常见问题总结 (1)
- 数据库SQL优化大总结 (1)
- 拦截器与过滤器的区别 (1)
- Struts2中拦截器与过滤器的区别及执行顺序 (1)
- Spring声明式事务管理与配置 (0)
- oracle OPERTION (1)
- java 高并发多线程开发 (1)
- Collection 与 map 接口相关集合 (1)
- 多线程开发实践 (1)
- JVM调优总结 转自 http://www.importnew.com/18694.html (1)
- redis 五种数据类型的使用场景 转自于 http://blog.csdn.net/gaogaoshan/article/details/41039581 (1)
- HttpWatch http基础 来自于http://blog.csdn.net/gaogaoshan/article/details/21237555 (1)
- maven 远程仓库 http://blog.csdn.net/gaogaoshan/article/details/40266779 (1)
- 生成Webservice客户端的4中方法 http://blog.csdn.net/gaogaoshan/article/details/8980775 (1)
- http://fgh2011.iteye.com/blog/1564283 (1)
- sleep和wait有什么区别 http://xiaowei2002.iteye.com/blog/2174188 (1)
- JDK中常用包及其类 常见的几种RuntimeException (1)
- Java的运行原理 (1)
- mybatis缓存的使用及理解 http://my.oschina.net/dxqr/blog/123163 (1)
- 软件架构设计分析 (1)
- redis技术总结 (3)
- java面试总结知识点 (1)
- ZooKeeper技术 (1)
- Hadoop (1)
- sso单点登录 (1)
- SpringIOC (1)
- 书签ssssssssssssssssssssss (1)
- spring事务的隔离级别 http://www.cnblogs.com/yangy608/archive/2011/06/29/2093478.html (1)
- 秒杀系统架构分析与实战 http://www.importnew.com/18920.html (1)
- oracle 连接plsql配置 (1)
- maven工程集成springmvc http://blog.csdn.net/fox_lht/article/details/16952683 (1)
- java类序列化与反序列化版本唯一号serialVersionUID (1)
- spring注解用法总结 (1)
- eclipse导入maven项目找不到资源文件方法 (1)
- dubbo (0)
- socket 网络编程 服务器与客户端 编程 (1)
- Thread与Runnable实现线程利用线程插队实现求和操作 (1)
- 生产者与消费者模式 (1)
- JAXB注解 java 关于xml的注解,自动生成xml文件 - @XML*** (1)
- xml 与JAVAbean转换 (1)
- MAP (2)
- decimalToString (1)
- 反编译插件 (0)
- 反编译插件 https://sourceforge.net/projects/jadclipse/?source=typ_redirect (1)
- AWX (1)
- 官网地址Dinp (1)
- public interface ExecutorService extends Executor (1)
- MAIN (1)
- 转自于 http://blog.csdn.net/lufeng20/article/details/24314381 (1)
- JaxbUtil (1)
- HttpXmlClient (0)
- Http post 请求 (1)
- URLDecoder (1)
- spdb (0)
- 订单号生成规则 (1)
- 距离0点毫秒数 (1)
- MyBatis存储过程调用java (1)
- Banks (1)
- 学习网址 (1)
- hots配置oracle数据库配置修改 (1)
- 支付宝文档 (1)
- Jadclipse (1)
- filter (0)
- Filter过滤器 (1)
- 工具类 fixbox (1)
- java quartz (0)
- java quartz 实现定时任务,每个礼拜一到礼拜五定时执行 (1)
- Thread (4)
- getResourceAsStream (1)
- BigData (1)
- 开源架构 (17)
- 架构 (0)
- 文件操作 (2)
- tools (20)
- 测试工具 (1)
- vm (1)
- mq (1)
- blog (1)
- 开源架构搭建技术 (6)
- JAVA细节技术点总结 (1)
- 优化技术 (1)
- LINUX命令使用 (1)
- spring (2)
- 大数据 (1)
- struts2 (1)
- python (1)
- pay (1)
- linux (1)
- 压力测试 (1)
- 代码检查插件 (1)
- 游戏端开发 (1)
- 微信开发相关 (1)
- 搜索引擎 (1)
- 网络技术 (1)
- 分布式部署 (1)
- 堆栈信息 (1)
最新评论
/**
* Copyright (c) 2011-2015 All Rights Reserved.
*/
package com.kame.micropay.netbank.service.adapter.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
//import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.kame.micropay.netbank.service.util.ObjectUtils;
/**
*
*
* @author
* @version $Id: HttpXmlClient.java 2015年10月28日 下午3:18:14 $
*/
@SuppressWarnings("deprecation")
public class HttpXmlClient {
private final static Logger log = LoggerFactory.getLogger(HttpXmlClient.class);
public static String postGB18030(String url, Map<?,?> paramMap) {
return post(url, paramMap, "GB18030");
}
public static String post(String url, Map<?,?> params, String toFilePath, String charsetName) {
if (StringUtils.isEmpty(url) || ObjectUtils.isEmpty(params)
|| StringUtils.isEmpty(toFilePath)) {
log.info("post the to file Path null.");
return "";
}
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");
PostMethod method = new PostMethod(url);
Iterator<?> it = params.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
Object o = params.get(key);
if (o != null && o instanceof String) {
method.addParameter(new NameValuePair(key.toString(), o.toString()));
}
if (o != null && o instanceof String[]) {
String[] s = (String[]) o;
if (s != null){
for (int i = 0; i < s.length; i++) {
method.addParameter(new NameValuePair(key.toString(), s[i]));
}
}
}
}
try {
int statusCode = httpClient.executeMethod(method);
log.info(method.getStatusLine().toString());
log.info("httpClientUtils:statusCode="+statusCode);
if (statusCode == HttpStatus.SC_OK) {
InputStream instream = method.getResponseBodyAsStream();
org.apache.commons.httpclient.Header contentHeader = method.getResponseHeader("Content-Disposition");
String filename = "";
if (contentHeader != null) {
org.apache.commons.httpclient.HeaderElement[] values = contentHeader.getElements();
if (values.length == 1) {
org.apache.commons.httpclient.NameValuePair param = values[0].getParameterByName("filename");
if (param != null) {
try {
filename = param.getValue();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
}
toFilePath = toFilePath + filename;
FileOutputStream fos = null;
try {
// 创建文件对象
File f = new File(toFilePath);
// 创建文件路径
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
// 写入文件
BufferedInputStream in=new BufferedInputStream(instream);
fos = new FileOutputStream(new File(toFilePath));
byte[] inputByte = new byte[1024];
int length=0;
while((length=in.read(inputByte,0,inputByte.length))>0){
fos.write(inputByte,0,length);
fos.flush();
}
} catch (Exception e) {
log.error("保存文件错误,path=" + toFilePath + ",url=" + url, e);
} finally {
try {
if (fos != null) fos.close();
} catch (Exception e) {
log.error("finally BufferedOutputStream shutdown close",e);
}
}
}
//content = new String(method.getResponseBody(), code);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if(method!=null)method.releaseConnection();
method = null;
httpClient = null;
}
return toFilePath;
}
public static String post(String url, Map<?,?> paramMap, String charsetName) {
String content = StringUtils.EMPTY;
if(StringUtils.isEmpty(url) || ObjectUtils.isEmpty(paramMap)){
return content;
}
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");
PostMethod method = new PostMethod(url);
Iterator<?> it = paramMap.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
Object o = paramMap.get(key);
if (o != null && o instanceof String) {
method.addParameter(new NameValuePair(key.toString(), o.toString()));
}
if (o != null && o instanceof String[]) {
String[] s = (String[]) o;
if (s != null){
for (int i = 0; i < s.length; i++) {
method.addParameter(new NameValuePair(key.toString(), s[i]));
}
}
}
}
try {
int statusCode = httpClient.executeMethod(method);
log.info(method.getStatusLine().toString());
log.info("httpClientUtils::statusCode="+statusCode);
content = new String(method.getResponseBody(), charsetName);
} catch (Exception e) {
log.error("time out");
log.error(e.getMessage(), e);
} finally {
if(method!=null)method.releaseConnection();
method = null;
httpClient = null;
}
return content;
}
/**
* POST方式发送
* @param url
* @param params
* @return
*/
public static String post(String url, Map<String, String> params) {
DefaultHttpClient httpclient = new DefaultHttpClient();
String body = null;
log.info("create httppost:" + url);
HttpPost post = postForm(url, params);
body = invoke(httpclient, post);
httpclient.getConnectionManager().shutdown();
return body;
}
public static String get(String url, String toFileDir, String charsetName) {
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(url);
try {
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode == HttpStatus.SC_OK) {
InputStream instream = getMethod.getResponseBodyAsStream();
org.apache.commons.httpclient.Header contentHeader = getMethod.getResponseHeader("Content-Disposition");
String filename = "";
if (contentHeader != null) {
org.apache.commons.httpclient.HeaderElement[] values = contentHeader.getElements();
if (values.length == 1) {
org.apache.commons.httpclient.NameValuePair param = values[0].getParameterByName("filename");
if (param != null) {
filename = param.getValue();
}
}
}
if (StringUtils.isEmpty(filename)) {
return new String(getMethod.getResponseBody(), charsetName);
}
toFileDir += filename;
FileOutputStream fos = null;
try {
// 创建文件对象
File f = new File(toFileDir);
// 创建文件路径
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
// 写入文件
BufferedInputStream in=new BufferedInputStream(instream);
fos = new FileOutputStream(f);
byte[] inputByte = new byte[1024];
int length=0;
while((length=in.read(inputByte,0,inputByte.length))>0){
fos.write(inputByte,0,length);
fos.flush();
}
} catch (Exception e) {
log.error("保存文件错误,path=" + toFileDir + ",url=" + url, e);
} finally {
IOUtils.closeQuietly(fos);
}
}
} catch (IOException e) {
log.error("保存文件错误:" + e.getMessage(), e);
} finally {
if(getMethod != null) {
getMethod.releaseConnection();
}
getMethod = null;
httpClient = null;
}
return toFileDir;
}
/**
* get 方式发送
* @param url
* @return
*/
public static String get(String url) {
DefaultHttpClient httpclient = new DefaultHttpClient();
String body = null;
log.info("create httppost:" + url);
HttpGet get = new HttpGet(url);
body = invoke(httpclient, get);
httpclient.getConnectionManager().shutdown();
return body;
}
private static String invoke(DefaultHttpClient httpclient,
HttpUriRequest httpost) {
HttpResponse response = sendRequest(httpclient, httpost);
String body = paseResponse(response);
return body;
}
private static String paseResponse(HttpResponse response) {
log.info("get response from http server..");
HttpEntity entity = response.getEntity();
log.info("response status: " + response.getStatusLine());
String charset = EntityUtils.getContentCharSet(entity);
log.info(charset);
String body = null;
try {
body = EntityUtils.toString(entity);
log.info(body);
} catch (ParseException e) {
log.error(e.getMessage(),e);
} catch (IOException e) {
log.error(e.getMessage(),e);
}
return body;
}
private static HttpResponse sendRequest(DefaultHttpClient httpclient,
HttpUriRequest httpost) {
log.info("execute post...");
HttpResponse response = null;
try {
response = httpclient.execute(httpost);
} catch (ClientProtocolException e) {
log.error(e.getMessage(),e);
} catch (IOException e) {
log.error(e.getMessage(),e);
}
return response;
}
private static HttpPost postForm(String url, Map<String, String> params){
HttpPost httpost = new HttpPost(url);
List<org.apache.http.NameValuePair> nvps = new ArrayList <org.apache.http.NameValuePair>();
Set<String> keySet = params.keySet();
for(String key : keySet) {
nvps.add(new BasicNameValuePair(key, params.get(key)));
}
try {
log.info("set utf-8 form entity to httppost");
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
log.error(e.getMessage(),e);
}
return httpost;
}
}
* Copyright (c) 2011-2015 All Rights Reserved.
*/
package com.kame.micropay.netbank.service.adapter.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
//import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.kame.micropay.netbank.service.util.ObjectUtils;
/**
*
*
* @author
* @version $Id: HttpXmlClient.java 2015年10月28日 下午3:18:14 $
*/
@SuppressWarnings("deprecation")
public class HttpXmlClient {
private final static Logger log = LoggerFactory.getLogger(HttpXmlClient.class);
public static String postGB18030(String url, Map<?,?> paramMap) {
return post(url, paramMap, "GB18030");
}
public static String post(String url, Map<?,?> params, String toFilePath, String charsetName) {
if (StringUtils.isEmpty(url) || ObjectUtils.isEmpty(params)
|| StringUtils.isEmpty(toFilePath)) {
log.info("post the to file Path null.");
return "";
}
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");
PostMethod method = new PostMethod(url);
Iterator<?> it = params.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
Object o = params.get(key);
if (o != null && o instanceof String) {
method.addParameter(new NameValuePair(key.toString(), o.toString()));
}
if (o != null && o instanceof String[]) {
String[] s = (String[]) o;
if (s != null){
for (int i = 0; i < s.length; i++) {
method.addParameter(new NameValuePair(key.toString(), s[i]));
}
}
}
}
try {
int statusCode = httpClient.executeMethod(method);
log.info(method.getStatusLine().toString());
log.info("httpClientUtils:statusCode="+statusCode);
if (statusCode == HttpStatus.SC_OK) {
InputStream instream = method.getResponseBodyAsStream();
org.apache.commons.httpclient.Header contentHeader = method.getResponseHeader("Content-Disposition");
String filename = "";
if (contentHeader != null) {
org.apache.commons.httpclient.HeaderElement[] values = contentHeader.getElements();
if (values.length == 1) {
org.apache.commons.httpclient.NameValuePair param = values[0].getParameterByName("filename");
if (param != null) {
try {
filename = param.getValue();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
}
toFilePath = toFilePath + filename;
FileOutputStream fos = null;
try {
// 创建文件对象
File f = new File(toFilePath);
// 创建文件路径
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
// 写入文件
BufferedInputStream in=new BufferedInputStream(instream);
fos = new FileOutputStream(new File(toFilePath));
byte[] inputByte = new byte[1024];
int length=0;
while((length=in.read(inputByte,0,inputByte.length))>0){
fos.write(inputByte,0,length);
fos.flush();
}
} catch (Exception e) {
log.error("保存文件错误,path=" + toFilePath + ",url=" + url, e);
} finally {
try {
if (fos != null) fos.close();
} catch (Exception e) {
log.error("finally BufferedOutputStream shutdown close",e);
}
}
}
//content = new String(method.getResponseBody(), code);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if(method!=null)method.releaseConnection();
method = null;
httpClient = null;
}
return toFilePath;
}
public static String post(String url, Map<?,?> paramMap, String charsetName) {
String content = StringUtils.EMPTY;
if(StringUtils.isEmpty(url) || ObjectUtils.isEmpty(paramMap)){
return content;
}
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");
PostMethod method = new PostMethod(url);
Iterator<?> it = paramMap.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
Object o = paramMap.get(key);
if (o != null && o instanceof String) {
method.addParameter(new NameValuePair(key.toString(), o.toString()));
}
if (o != null && o instanceof String[]) {
String[] s = (String[]) o;
if (s != null){
for (int i = 0; i < s.length; i++) {
method.addParameter(new NameValuePair(key.toString(), s[i]));
}
}
}
}
try {
int statusCode = httpClient.executeMethod(method);
log.info(method.getStatusLine().toString());
log.info("httpClientUtils::statusCode="+statusCode);
content = new String(method.getResponseBody(), charsetName);
} catch (Exception e) {
log.error("time out");
log.error(e.getMessage(), e);
} finally {
if(method!=null)method.releaseConnection();
method = null;
httpClient = null;
}
return content;
}
/**
* POST方式发送
* @param url
* @param params
* @return
*/
public static String post(String url, Map<String, String> params) {
DefaultHttpClient httpclient = new DefaultHttpClient();
String body = null;
log.info("create httppost:" + url);
HttpPost post = postForm(url, params);
body = invoke(httpclient, post);
httpclient.getConnectionManager().shutdown();
return body;
}
public static String get(String url, String toFileDir, String charsetName) {
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(url);
try {
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode == HttpStatus.SC_OK) {
InputStream instream = getMethod.getResponseBodyAsStream();
org.apache.commons.httpclient.Header contentHeader = getMethod.getResponseHeader("Content-Disposition");
String filename = "";
if (contentHeader != null) {
org.apache.commons.httpclient.HeaderElement[] values = contentHeader.getElements();
if (values.length == 1) {
org.apache.commons.httpclient.NameValuePair param = values[0].getParameterByName("filename");
if (param != null) {
filename = param.getValue();
}
}
}
if (StringUtils.isEmpty(filename)) {
return new String(getMethod.getResponseBody(), charsetName);
}
toFileDir += filename;
FileOutputStream fos = null;
try {
// 创建文件对象
File f = new File(toFileDir);
// 创建文件路径
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
// 写入文件
BufferedInputStream in=new BufferedInputStream(instream);
fos = new FileOutputStream(f);
byte[] inputByte = new byte[1024];
int length=0;
while((length=in.read(inputByte,0,inputByte.length))>0){
fos.write(inputByte,0,length);
fos.flush();
}
} catch (Exception e) {
log.error("保存文件错误,path=" + toFileDir + ",url=" + url, e);
} finally {
IOUtils.closeQuietly(fos);
}
}
} catch (IOException e) {
log.error("保存文件错误:" + e.getMessage(), e);
} finally {
if(getMethod != null) {
getMethod.releaseConnection();
}
getMethod = null;
httpClient = null;
}
return toFileDir;
}
/**
* get 方式发送
* @param url
* @return
*/
public static String get(String url) {
DefaultHttpClient httpclient = new DefaultHttpClient();
String body = null;
log.info("create httppost:" + url);
HttpGet get = new HttpGet(url);
body = invoke(httpclient, get);
httpclient.getConnectionManager().shutdown();
return body;
}
private static String invoke(DefaultHttpClient httpclient,
HttpUriRequest httpost) {
HttpResponse response = sendRequest(httpclient, httpost);
String body = paseResponse(response);
return body;
}
private static String paseResponse(HttpResponse response) {
log.info("get response from http server..");
HttpEntity entity = response.getEntity();
log.info("response status: " + response.getStatusLine());
String charset = EntityUtils.getContentCharSet(entity);
log.info(charset);
String body = null;
try {
body = EntityUtils.toString(entity);
log.info(body);
} catch (ParseException e) {
log.error(e.getMessage(),e);
} catch (IOException e) {
log.error(e.getMessage(),e);
}
return body;
}
private static HttpResponse sendRequest(DefaultHttpClient httpclient,
HttpUriRequest httpost) {
log.info("execute post...");
HttpResponse response = null;
try {
response = httpclient.execute(httpost);
} catch (ClientProtocolException e) {
log.error(e.getMessage(),e);
} catch (IOException e) {
log.error(e.getMessage(),e);
}
return response;
}
private static HttpPost postForm(String url, Map<String, String> params){
HttpPost httpost = new HttpPost(url);
List<org.apache.http.NameValuePair> nvps = new ArrayList <org.apache.http.NameValuePair>();
Set<String> keySet = params.keySet();
for(String key : keySet) {
nvps.add(new BasicNameValuePair(key, params.get(key)));
}
try {
log.info("set utf-8 form entity to httppost");
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
log.error(e.getMessage(),e);
}
return httpost;
}
}
相关推荐
在"HttpXmlServer"和"HttpXmlClient"这两个文件中,我们可以预见到以下操作: 1. **HttpXmlServer**:服务器端会使用XStream将Java对象转换为XML字符串,然后通过HttpClient发送给客户端。可能还会包含监听特定端口...
httpclient需要的各种jar包 commons-codec-1.7.jar commons-httpclient.jar commons-logging-1.1.1.jar httpclient-4.2.2.jar httpcore-4.2.2.jar
基于springboot大学生就业信息管理系统源码数据库文档.zip
基于java的驾校收支管理可视化平台的开题报告
时间序列 原木 间隔5秒钟 20241120
毕业设计&课设_基于 Vue 的电影在线预订与管理系统:后台 Java(SSM)代码,为毕业设计项目.zip
基于springboot课件通中小学教学课件共享平台源码数据库文档.zip
基于java的网上购物商城的开题报告
Delphi人脸检测与识别Demo1fdef-main.zip
基于java的咖啡在线销售系统的开题报告
基于java的自助医疗服务系统的开题报告.docx
内容概要:本文档全面介绍了Visual Basic(VB)编程语言的基础知识和高级应用。首先概述了VB的基本特性和开发环境,随后详细讲述了VB的数据类型、变量、运算符、控制结构、数组、过程与函数、变量作用域等内容。接着介绍了窗体设计、控件使用、菜单与工具栏的设计,文件操作、数据库访问等关键知识点。最后讨论了VB的学习方法、发展历史及其在桌面应用、Web应用、数据库应用、游戏开发和自动化脚本编写等领域的广泛应用前景。 适合人群:初学者和中级程序员,尤其是希望快速掌握Windows桌面应用开发的人群。 使用场景及目标:①掌握VB的基础语法和开发环境;②学会使用VB创建复杂的用户界面和功能完整的应用程序;③理解数据库操作、文件管理和网络编程等高级主题。 其他说明:Visual Basic是一种简单易学且功能强大的编程语言,尤其适合用于开发Windows桌面应用。文中不仅覆盖了基础知识,还包括了大量的实用案例和技术细节,帮助读者快速提升编程技能。
基于java的疫情期间高校防控系统开题报告.docx
基于springboot+vue社区老年人帮扶系统源码数据库文档.zip
基于java的超市商品管理系统的开题报告.docx
基于SpringBoot房屋买卖平台源码数据库文档.zip
xdu限通院23微处理器系统与应用大作业(两只老虎),适应于汇编语言keil软件,
<项目介绍> - 新闻类网站系统,基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发,高分成品毕业设计,附带往届论文 - 不懂运行,下载完可以私聊问,可远程教学 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
基于java的学生网上请假系统的开题报告.docx
社会经济繁荣发展的今天,电子商务得到了飞速发展,网上交易越来越彰显出其独特的优越性,在人们的日常生活中,出现了各种类型的交易网站。其中一个就是车辆易主交易网站,它是一个服务于用户买卖二手车辆的交易网站,为用户提供了平等互利、方便快捷的网上交易平台,通过这一类型的网站,用户可自由出售和购买车辆。 本课题主要根据车辆本身的特性,充分发挥互联网的特点与优势,构建一个以二手车辆为商品、基于互联网平台的车辆易主业务交易管理系统,并根据车辆易主业务交易管理系统的应用需求,进行需求分析,进而对网站系统作规划设计。采用IDEA为运行平台,以SSH为框架,运用HTML语言、JSP技术、MySql数据库、JSP与后台数据库链接等关键技术建设二手车网上交易系统,构建车辆易主交易系统的会员注册与登录,网站首页展示、用户发布商品车辆,用户求购商品车辆,分页浏览、购物系统、用户后台管理、管理员用户后台管理等功能,并使这些功能得以实现并更好为用户服务。网站整体构建完成且测试成功后,用户可以进入网站进行注册、登录,登录后,用户可以在网站上发布自己的闲置车辆或者寻找想要购买的车辆,还可以收藏车辆,管理发布和收藏的车辆,