- 浏览: 100523 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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
电子商务之价格优化算法:梯度下降:机器学习在价格优化中的角色.docx
ToadforOracle与Oracle数据库版本兼容性教程.docx
360浏览器银河麒麟版 for X86 适配兆芯 / 海光 / intel / AMD CPU
使用React.js构建,提供多种主题可供选择,并且易于定制。该项目旨在帮助开发者和自由职业者创建自己的个性化投资组合。 主要功能点 多种主题可供选择,包括绿色、黑白、蓝色、红色、橙色、紫色、粉色和黄色 易于定制,可以在src/data文件夹中更新个人信息 包含主页、关于、简历、教育、技能、经验、项目、成就、服务、推荐信、博客和联系等多个部分 支持通过Google表单收集联系信息 提供SEO优化建议 支持多种部署方式,如Netlify、Firebase、Heroku和GitHub Pages 技术栈主要 React.js Material-UI Axios React-fast-marquee React-helmet React-icons React-reveal React-router-dom React-router-hash-link React-slick Slick-carousel Validator
中小型企业财务管理系统 SSM毕业设计 附带论文 启动教程:https://www.bilibili.com/video/BV1GK1iYyE2B
python whl离线安装包 pip安装失败可以尝试使用whl离线安装包安装 第一步 下载whl文件,注意需要与python版本配套 python版本号、32位64位、arm或amd64均有区别 第二步 使用pip install XXXXX.whl 命令安装,如果whl路径不在cmd窗口当前目录下,需要带上路径 WHL文件是以Wheel格式保存的Python安装包, Wheel是Python发行版的标准内置包格式。 在本质上是一个压缩包,WHL文件中包含了Python安装的py文件和元数据,以及经过编译的pyd文件, 这样就使得它可以在不具备编译环境的条件下,安装适合自己python版本的库文件。 如果要查看WHL文件的内容,可以把.whl后缀名改成.zip,使用解压软件(如WinRAR、WinZIP)解压打开即可查看。 为什么会用到whl文件来安装python库文件呢? 在python的使用过程中,我们免不了要经常通过pip来安装自己所需要的包, 大部分的包基本都能正常安装,但是总会遇到有那么一些包因为各种各样的问题导致安装不了的。 这时我们就可以通过尝试去Python安装包大全中(whl包下载)下载whl包来安装解决问题。
电子商务之价格优化算法:线性回归:价格优化策略实施.docx
内容概要:报告详细介绍了企业数字化转型的驱动因素、数字化转型方案分类及其应用场景,重点关注了云计算、超连接、数字孪生、人工智能、分布式账本、增材制造、人机接口、数据共享、工业物联网等关键技术。这些技术不仅支持了企业的运营效率提升和业务模式创新,也为实现更快、更开放、更高效的数字化转型提供了支撑。报告最后提出了企业实施数字化转型的六个步骤。 适合人群:企业高级管理人员、技术人员、咨询顾问,以及对工业数字化转型感兴趣的读者。 使用场景及目标:帮助企业制定和实施数字化转型策略,优化运营模式,提升业务效率,增强市场竞争力。同时,也可作为政府部门、研究机构和行业协会的参考文献。 其他说明:报告中提到的关键技术及其应用场景对企业数字化转型具有重要的指导意义,特别是对于那些希望通过数字化转型实现业务创新和升级的企业。
基于java的线上选课系统的设计与实现答辩PPT.pptx
安装前的准备 1、安装Python:确保你的计算机上已经安装了Python。你可以在命令行中输入python --version或python3 --version来检查是否已安装以及安装的版本。 个人建议:在anaconda中自建不同python版本的环境,方法如下(其他版本照葫芦画瓢): 比如创建python3.8环境,anaconda命令终端输入:conda create -n py38 python==3.8 2、安装pip:pip是Python的包管理工具,用于安装和管理Python包。你可以通过输入pip --version或pip3 --version来检查pip是否已安装。 安装WHL安装包 1、打开命令行(或打开anaconda命令行终端): 在Windows上,你可以搜索“cmd”或“命令提示符”并打开它。 在macOS或Linux上,你可以打开“终端”。 2、cd到whl文件所在目录安装: 使用cd命令导航到你下载的whl文件所在的文件夹。 终端输入:pip install xxx.whl安装即可(xxx.whl指的是csdn下载解压出来的whl) 3、等待安装完成: 命令行会显示安装进度,并在安装完成后返回提示符。 以上是简单安装介绍,小白也能会,简单好用,从此再也不怕下载安装超时问题。 使用过程遇到问题可以私信,我可以帮你解决! 收起
电子商务之价格优化算法:贝叶斯定价:贝叶斯网络在电子商务定价中的应用.docx
IMG_20241105_235746.jpg
基于java的毕业设计选题系统答辩PPT.pptx
专升本考试资料全套.7z
Trustwave DbProtect:数据库活动监控策略制定.docx
基于VB的程序实例,可供参考学习使用
本压缩包资源说明,你现在往下拉可以看到压缩包内容目录 我是批量上传的基于SpringBoot+Vue的项目,所以描述都一样;有源码有数据库脚本,系统都是测试过可运行的,看文件名即可区分项目~ |Java|SpringBoot|Vue|前后端分离| 开发语言:Java 框架:SpringBoot,Vue JDK版本:JDK1.8 数据库:MySQL 5.7+(推荐5.7,8.0也可以) 数据库工具:Navicat 开发软件: idea/eclipse(推荐idea) Maven包:Maven3.3.9+ 系统环境:Windows/Mac
该源码项目是一款基于Thinkphp5框架的Java插件设计,包含114个文件,其中Java源文件60个,PNG图片32个,XML配置文件7个,GIF图片7个,Git忽略文件1个,LICENSE文件1个,Markdown文件1个,Xmind文件1个,Idea项目文件1个,以及JAR文件1个。