- 浏览: 105933 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (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
内容概要:本文详细介绍了基于DSP28035的CAN在线升级程序及其Bootloader开发服务。主要内容涵盖CAN通讯协议的设计与实现,包括CAN模块初始化、Hex文件解析、内存分配以及应用程序跳转等关键技术点。此外,还讨论了上位机软件的开发选择和技术难点,如超时检测、CRC校验、中断向量表重映射等。文中不仅提供了具体的代码示例,还分享了许多实践经验,如避免内存越界、处理地址扩展等问题的方法。 适合人群:从事嵌入式系统开发的技术人员,尤其是那些对DSP28035感兴趣或正在使用该处理器进行项目的开发者。 使用场景及目标:适用于需要实现远程固件更新的嵌入式设备制造商,旨在提高产品维护效率并减少物理干预的需求。通过学习本文,读者可以掌握如何构建一个稳定可靠的CAN在线升级解决方案。 其他说明:文章强调了协议设计的重要性,并指出了一些常见的错误和陷阱,帮助读者避开这些问题。同时,作者还提到了一些优化技巧,比如利用DMA加速数据传输、合理规划内存布局等,以确保系统的高性能和稳定性。
内容概要:本文详细介绍了基于UDS(Unified Diagnostic Services)协议的Bootloader在Autosar架构下的定制开发过程。主要内容涵盖Autosar架构与DCM(诊断通信管理)模块的集成,以及针对不同系列芯片(如NXP S32K、Infineon TC275等)的具体实现细节。文中通过具体的代码示例展示了从初始化、诊断服务处理到跳转应用程序的全过程,并讨论了不同芯片之间的差异及其应对策略。此外,还涉及了存储器管理、数据传输优化和安全启动等方面的内容。 适合人群:从事汽车电子开发的专业人士,尤其是对Bootloader开发感兴趣的工程师和技术人员。 使用场景及目标:适用于需要深入了解和实现基于UDS协议的Bootloader定制项目的团队。主要目标是提高汽车电子系统的诊断效率和可靠性,同时确保不同芯片平台间的兼容性和性能最优化。 其他说明:文章不仅提供了理论指导,还包括大量实用的代码片段和实践经验分享,帮助读者更好地理解和应用于实际项目中。
内容概要:本文详细介绍了如何通过Modbus协议实现昆仑通态触摸屏与台达VFD-M系列变频器之间的通讯,具体涵盖了硬件接线、关键参数设置、MCGS组态环境中的设备配置、变量定义、界面设计及脚本编写等内容。文中不仅提供了详细的参数设置方法,还分享了一些常见的调试技巧和故障排查方法,如硬件接线注意事项、参数设置要点、通讯故障解决措施等。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些需要进行触摸屏与变频器通讯集成工作的人员。 使用场景及目标:适用于需要通过触摸屏远程控制变频器的应用场景,如工厂自动化生产线、机械设备控制等。目标是让读者能够独立完成从硬件连接到软件编程的整个通讯系统搭建过程。 其他说明:文章强调了实际操作中的注意事项和容易忽视的细节,如硬件接线的特殊性、参数设置的准确性、通讯协议的具体应用等,有助于提高项目的成功率和稳定性。同时,提供了丰富的调试工具和方法,帮助读者快速定位和解决问题。
内容概要:本文详细介绍了一种750W高功率因数(PF)充电机电源方案,采用UCC28070、ST6599和PIC16F193X三款芯片组合。UCC28070用于功率因数校正(PFC),通过交错式升压电路提升PF值;ST6599负责LLC谐振变换器,确保高效功率转换;PIC16F193X作为微控制器进行智能控制。文中不仅提供了详细的原理图、设计文件和烧录程序,还分享了具体的应用代码和调试技巧。此外,引用了华南理工大学硕士学位论文,深入探讨了设计优化方法。 适合人群:电源设计工程师、电子工程专业学生、对高效电源设计感兴趣的开发者。 使用场景及目标:适用于需要高功率因数和高效能的充电机应用场景,如电动汽车充电桩、数据中心备用电源等。目标是帮助读者掌握高效电源设计的技术细节,提升产品性能。 其他说明:本文不仅提供了硬件设计思路,还包括软件编程实例,如PFC控制算法、LLC频率调整、故障保护机制等。同时强调了实际应用中的注意事项,如寄存器配置、元件选型、PCB布局等。
内容概要:本文详细介绍了基于200smart PLC和昆仑通态触摸屏构建的一拖三恒压供水系统的实现方法及其调试经验。主要内容涵盖系统架构设计、PID控制参数整定、触摸屏配置、水泵轮换逻辑以及常见的调试技巧和注意事项。文中强调了PID控制在变频器调度中的重要性,提供了具体的代码示例和技术细节,如PID输出限幅处理、Modbus通信映射、压力反馈处理等。此外,作者还分享了许多宝贵的实战经验和教训,如避免在触摸屏上进行复杂运算、确保硬件布局合理性等。 适合人群:从事自动化控制系统设计与调试的技术人员,尤其是对PID控制和PLC编程有一定基础的研发人员。 使用场景及目标:适用于需要精确控制供水压力的工业场合,如小区二次供水、厂房循环水系统等。目标是帮助技术人员理解和掌握一拖三恒压供水系统的实现方法,提高系统的稳定性和可靠性。 其他说明:文中提到的具体参数和代码片段可供参考,但在实际应用中需根据具体情况进行适当调整。
该资源为natsort-3.1.2.tar.gz,欢迎下载使用哦!
该资源为natsort-2.0.0-py2.7.egg,欢迎下载使用哦!
内容概要:本文详细阐述了DeepSeek大模型在服装行业的应用方案,旨在通过人工智能技术提升服装企业的运营效率和市场竞争力。文章首先介绍了服装行业的现状与挑战,指出传统模式难以应对复杂的市场变化。DeepSeek大模型凭借其强大的数据分析和模式识别能力,能够精准预测市场趋势、优化供应链管理、提升产品设计效率,并实现个性化推荐。具体应用场景包括设计灵感生成、自动化设计、虚拟试衣、需求预测、生产流程优化、精准营销、智能客服、用户体验提升等。此外,文章还探讨了数据安全与隐私保护的重要性,以及技术实施与集成的具体步骤。最后,文章展望了未来市场扩展和技术升级的方向,强调了持续优化和合作的重要性。 适用人群:服装行业的企业管理层、技术负责人、市场和销售团队、供应链管理人员。 使用场景及目标:①通过市场趋势预测和用户偏好分析,提升设计效率和产品创新;②优化供应链管理,减少库存积压和生产浪费;③实现精准营销,提高客户满意度和转化率;④通过智能客服和虚拟试衣技术,提升用户体验;⑤确保数据安全和隐私保护,建立用户信任。 阅读建议:此资源不仅涵盖技术实现的细节,还涉及业务流程的优化和管理策略的调整,建议读者结合实际业务需求,重点关注与自身工作相关的部分,并逐步推进技术的应用和创新。
内容概要:本文详细介绍了一套基于三菱FX3U PLC的完整开发方案,涵盖硬件设计和软件编程两个方面。硬件部分包括详细的原理图、PCB文件以及关键组件的选择和布局技巧,如电源模块、光耦隔离电路、继电器输出等。软件部分则涉及梯形图编程和C语言开发,展示了如何利用GX Works2进行梯形图编程,以及如何使用Keil进行C语言开发,实现复杂的控制逻辑和高效的任务调度。此外,还提供了许多调试技巧和注意事项,帮助开发者避免常见错误并提高开发效率。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是对PLC开发感兴趣的初学者和有一定经验的研发人员。 使用场景及目标:适用于需要深入了解PLC底层运作机制、掌握硬件设计和软件编程技能的场合。目标是通过实际案例和详细指导,帮助读者快速上手三菱FX3U PLC的开发,实现高效的控制系统设计。 其他说明:文中提供的代码片段和设计思路不仅有助于理解PLC的工作原理,还可以作为实际项目的参考,加速开发进程。同时,文中还分享了许多实践经验,对于解决实际开发中的问题非常有帮助。
甲壳虫adb助手安全下载.apk
内容概要:本文详细介绍了基于SJA1000协议栈的FPGA实现CAN总线控制器的全过程。涵盖了Verilog和VHDL双版本源码、Altera和Xilinx平台的具体实现细节以及完整的testbench程序。文中深入探讨了状态机控制器、CRC校验器、位时序单元和FIFO缓存四大核心模块的设计思路和技术要点。同时,提供了详细的仿真验证方法和优化技巧,如随机延迟测试、时钟管理配置等。此外,还附带了Quartus II 13.0和ISE14.7的安装指南及常见问题解决方案。 适合人群:FPGA开发者、嵌入式系统工程师、电子工程专业学生及研究人员。 使用场景及目标:适用于希望深入了解CAN总线控制器硬件实现的技术人员,帮助他们快速掌握FPGA开发流程,完成从代码编写到仿真的全流程操作。目标是在实际项目中高效实现CAN总线通信功能,提升系统的稳定性和性能。 其他说明:本文不仅提供完整的工程代码和仿真工具,还包括详细的开发板引脚约束配置和跨平台移植指导,确保用户能够顺利进行开发和调试。
中兴光猫G7610V2-V3.0.0P1N12固件
流变学仿真方法:流变学仿真软件介绍.zip
内容概要:本文详细介绍了如何利用昆仑通态触摸屏与ABB变频器ACS510通过Modbus RTU协议实现直接通讯,构建高效的恒压供水系统。文中涵盖了硬件连接、参数设置、脚本编写、策略配置等方面的内容。通过这种方式,不仅简化了操作流程,还提高了系统的稳定性和可靠性。具体而言,文章首先解释了选择这两者的理由,接着逐步讲解了硬件接线方法、参数配置细节、脚本控制逻辑以及一些常见的调试技巧。此外,还特别提到了夜间降压逻辑、故障复位按钮等高级功能的应用。 适合人群:从事自动化控制系统设计、维护的技术人员,尤其是对恒压供水系统感兴趣的工程师。 使用场景及目标:适用于需要稳定水压供应的场合,如居民小区、商业建筑等。主要目标是通过简化操作流程、提高系统稳定性,从而实现更加智能和高效的供水管理。 其他说明:文章提供了大量实际案例和技术细节,帮助读者更好地理解和应用相关技术。同时,强调了硬件和软件相结合的重要性,分享了许多实用的经验和技巧。
内容概要:本文全面介绍了移动开发的相关知识,首先概述了移动开发的概念及其重要性,随后详细介绍了iOS和Android两大主流平台的开发语言、环境及工具,并涵盖了跨平台开发框架如React Native、Flutter等。接着列举了版本控制、构建自动化、UI设计及调试测试等常用工具。文章还提供了丰富的学习资源,包括官方文档、书籍和视频教程。此外,针对移动开发中常见的性能优化、兼容性、安全性和用户体验设计等问题进行了探讨,并通过社交、电商、健身追踪和地图导航等实际案例展示了不同应用场景的技术实现。最后推荐了一些适合初学者的项目,鼓励读者实践所学知识。; 适合人群:对移动开发感兴趣的初学者,以及希望深入了解移动开发技术的开发者。; 使用场景及目标:①了解iOS和Android平台的开发环境和技术栈;②掌握跨平台开发工具的选择与使用;③学习如何解决移动开发中的性能、兼容性、安全等常见问题;④通过实战案例掌握不同类型应用的核心技术实现。; 其他说明:移动开发是一个不断发展的领域,文中提到的技术和工具可能会随行业发展而更新,建议读者持续关注最新动态并不断学习新技能。
基于python的多种函数递归与斐波那契数列文件
内容概要:本文详细介绍了复盘的概念、操作手法、应用场景及其对企业及个人成长的重要性。复盘源自围棋术语,指对过去的经验进行回顾和反思,以从中学习和改进。文章阐述了复盘的五大核心要素:回顾目标、评估结果、分析原因、总结经验教训和提出改进建议。复盘不仅适用于个人成长,还广泛应用于企业管理和项目管理中,能够帮助企业提升执行力、改善决策流程、优化运营效率,并最终推动组织学习和发展。文中特别强调了复盘在军队、联想集团和英国石油公司(BP)中的成功实践。 适合人群:企业管理者、项目经理、团队领导者及希望提升自我反思和学习能力的职场人士。 使用场景及目标:①帮助个人和团队从过去的经历中吸取教训,避免重复错误;②通过系统的反思和总结,提升团队的协作效率和创新能力;③促进企业内部的知识共享和文化传播,构建学习型组织;④为企业战略调整提供数据支持,确保战略目标的有效落地。 其他说明:为了使复盘成为一种常态化的工作方法和习惯,组织应加强培训,培养专业的引导者,并将复盘融入日常管理流程中。此外,复盘的成功实施还需要营造开放、坦诚的文化氛围,鼓励全员积极参与。复盘不仅仅是回顾过去,更是面向未来的持续改进工具。