- 浏览: 102732 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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)
最新评论
package com.tty.youl.bank.service.util;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
/**
* 财付通http或者https网络通信客户端<br/>
* ========================================================================<br/>
* api说明:<br/>
* setReqContent($reqContent),设置请求内容,无论post和get,都用get方式提供<br/>
* getResContent(), 获取应答内容<br/>
* setMethod(method),设置请求方法,post或者get<br/>
* getErrInfo(),获取错误信息<br/>
* setCertInfo(certFile, certPasswd),设置证书,双向https时需要使用<br/>
* setCaInfo(caFile), 设置CA,格式未pem,不设置则不检查<br/>
* setTimeOut(timeOut), 设置超时时间,单位秒<br/>
* getResponseCode(), 取返回的http状态码<br/>
* call(),真正调用接口<br/>
* getCharset()/setCharset(),字符集编码<br/>
*
* ========================================================================<br/>
*
*/
public class TenpayHttpClient {
private static final String USER_AGENT_VALUE = "Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)";
private static final String JKS_CA_FILENAME = "tenpay_cacert.jks";
private static final String JKS_CA_ALIAS = "tenpay";
private static final String JKS_CA_PASSWORD = "";
/** ca证书文件 */
private File caFile;
/** 证书文件 */
private File certFile;
/** 证书密码 */
private String certPasswd;
/** 请求内容,无论post和get,都用get方式提供 */
private String reqContent;
/** 应答内容 */
private String resContent;
/** 请求方法 */
private String method;
/** 错误信息 */
private String errInfo;
/** 超时时间,以秒为单位 */
private int timeOut;
/** http应答编码 */
private int responseCode;
/** 字符编码 */
private String charset;
private InputStream inputStream;
public TenpayHttpClient() {
this.caFile = null;
this.certFile = null;
this.certPasswd = "";
this.reqContent = "";
this.resContent = "";
this.method = "POST";
this.errInfo = "";
this.timeOut = 30;//30秒
this.responseCode = 0;
this.charset = "GBK";
this.inputStream = null;
}
/**
* 设置证书信息
* @param certFile 证书文件
* @param certPasswd 证书密码
*/
public void setCertInfo(File certFile, String certPasswd) {
this.certFile = certFile;
this.certPasswd = certPasswd;
}
/**
* 设置ca
* @param caFile
*/
public void setCaInfo(File caFile) {
this.caFile = caFile;
}
/**
* 设置请求内容
* @param reqContent 表求内容
*/
public void setReqContent(String reqContent) {
this.reqContent = reqContent;
}
/**
* 获取结果内容
* @return String
* @throws IOException
*/
public String getResContent() {
try {
this.doResponse();
} catch (IOException e) {
this.errInfo = e.getMessage();
//return "";
}
return this.resContent;
}
/**
* 设置请求方法post或者get
* @param method 请求方法post/get
*/
public void setMethod(String method) {
this.method = method;
}
/**
* 获取错误信息
* @return String
*/
public String getErrInfo() {
return this.errInfo;
}
/**
* 设置超时时间,以秒为单位
* @param timeOut 超时时间,以秒为单位
*/
public void setTimeOut(int timeOut) {
this.timeOut = timeOut;
}
/**
* 获取http状态码
* @return int
*/
public int getResponseCode() {
return this.responseCode;
}
/**
* 执行http调用。true:成功 false:失败
* @return boolean
*/
public boolean call() {
boolean isRet = false;
//http
if(null == this.caFile && null == this.certFile) {
try {
this.callHttp();
isRet = true;
} catch (IOException e) {
this.errInfo = e.getMessage();
}
return isRet;
}
//https
try {
this.callHttps();
isRet = true;
} catch (UnrecoverableKeyException e) {
this.errInfo = e.getMessage();
} catch (KeyManagementException e) {
this.errInfo = e.getMessage();
} catch (CertificateException e) {
this.errInfo = e.getMessage();
} catch (KeyStoreException e) {
this.errInfo = e.getMessage();
} catch (NoSuchAlgorithmException e) {
this.errInfo = e.getMessage();
} catch (IOException e) {
this.errInfo = e.getMessage();
}
return isRet;
}
protected void callHttp() throws IOException {
if("POST".equals(this.method.toUpperCase())) {
String url = HttpClientUtil.getURL(this.reqContent);
String queryString = HttpClientUtil.getQueryString(this.reqContent);
byte[] postData = queryString.getBytes(this.charset);
this.httpPostMethod(url, postData);
return ;
}
this.httpGetMethod(this.reqContent);
}
protected void callHttps() throws IOException, CertificateException,
KeyStoreException, NoSuchAlgorithmException,
UnrecoverableKeyException, KeyManagementException {
// ca目录
String caPath = this.caFile.getParent();
File jksCAFile = new File(caPath + "/"
+ TenpayHttpClient.JKS_CA_FILENAME);
if (!jksCAFile.isFile()) {
X509Certificate cert = (X509Certificate) HttpClientUtil
.getCertificate(this.caFile);
FileOutputStream out = new FileOutputStream(jksCAFile);
// store jks file
HttpClientUtil.storeCACert(cert, TenpayHttpClient.JKS_CA_ALIAS,
TenpayHttpClient.JKS_CA_PASSWORD, out);
out.close();
}
FileInputStream trustStream = new FileInputStream(jksCAFile);
FileInputStream keyStream = new FileInputStream(this.certFile);
SSLContext sslContext = HttpClientUtil.getSSLContext(trustStream,
TenpayHttpClient.JKS_CA_PASSWORD, keyStream, this.certPasswd);
//关闭流
keyStream.close();
trustStream.close();
if("POST".equals(this.method.toUpperCase())) {
String url = HttpClientUtil.getURL(this.reqContent);
String queryString = HttpClientUtil.getQueryString(this.reqContent);
byte[] postData = queryString.getBytes(this.charset);
this.httpsPostMethod(url, postData, sslContext);
return ;
}
this.httpsGetMethod(this.reqContent, sslContext);
}
public boolean callHttpPost(String url, String postdata) {
boolean flag = false;
byte[] postData;
try {
postData = postdata.getBytes(this.charset);
this.httpPostMethod(url, postData);
flag = true;
} catch (IOException e1) {
e1.printStackTrace();
}
return flag;
}
/**
* 以http post方式通信
* @param url
* @param postData
* @throws IOException
*/
protected void httpPostMethod(String url, byte[] postData) throws IOException {
HttpURLConnection conn = HttpClientUtil.getHttpURLConnection(url);
this.doPost(conn, postData);
}
/**
* 以http get方式通信
*
* @param url
* @throws IOException
*/
protected void httpGetMethod(String url) throws IOException {
HttpURLConnection httpConnection =
HttpClientUtil.getHttpURLConnection(url);
this.setHttpRequest(httpConnection);
httpConnection.setRequestMethod("GET");
this.responseCode = httpConnection.getResponseCode();
this.inputStream = httpConnection.getInputStream();
}
/**
* 以https get方式通信
* @param url
* @param sslContext
* @throws IOException
*/
protected void httpsGetMethod(String url, SSLContext sslContext)
throws IOException {
SSLSocketFactory sf = sslContext.getSocketFactory();
HttpsURLConnection conn = HttpClientUtil.getHttpsURLConnection(url);
conn.setSSLSocketFactory(sf);
this.doGet(conn);
}
protected void httpsPostMethod(String url, byte[] postData,
SSLContext sslContext) throws IOException {
SSLSocketFactory sf = sslContext.getSocketFactory();
HttpsURLConnection conn = HttpClientUtil.getHttpsURLConnection(url);
conn.setSSLSocketFactory(sf);
this.doPost(conn, postData);
}
/**
* 设置http请求默认属性
* @param httpConnection
*/
protected void setHttpRequest(HttpURLConnection httpConnection) {
//设置连接超时时间
httpConnection.setConnectTimeout(this.timeOut * 1000);
//User-Agent
httpConnection.setRequestProperty("User-Agent",
TenpayHttpClient.USER_AGENT_VALUE);
//不使用缓存
httpConnection.setUseCaches(false);
//允许输入输出
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
}
/**
* 处理应答
* @throws IOException
*/
protected void doResponse() throws IOException {
if(null == this.inputStream) {
return;
}
//获取应答内容
this.resContent=HttpClientUtil.InputStreamTOString(this.inputStream,this.charset);
//关闭输入流
this.inputStream.close();
}
/**
* post方式处理
* @param conn
* @param postData
* @throws IOException
*/
protected void doPost(HttpURLConnection conn, byte[] postData) throws IOException {
// 以post方式通信
conn.setRequestMethod("POST");
// 设置请求默认属性
this.setHttpRequest(conn);
// Content-Type
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedOutputStream out = new BufferedOutputStream(conn.getOutputStream());
final int len = 1024; // 1KB
HttpClientUtil.doOutput(out, postData, len);
// 关闭流
out.close();
// 获取响应返回状态码
this.responseCode = conn.getResponseCode();
// 获取应答输入流
this.inputStream = conn.getInputStream();
}
/**
* get方式处理
* @param conn
* @throws IOException
*/
protected void doGet(HttpURLConnection conn) throws IOException {
//以GET方式通信
conn.setRequestMethod("GET");
//设置请求默认属性
this.setHttpRequest(conn);
//获取响应返回状态码
this.responseCode = conn.getResponseCode();
//获取应答输入流
this.inputStream = conn.getInputStream();
}
}
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
/**
* 财付通http或者https网络通信客户端<br/>
* ========================================================================<br/>
* api说明:<br/>
* setReqContent($reqContent),设置请求内容,无论post和get,都用get方式提供<br/>
* getResContent(), 获取应答内容<br/>
* setMethod(method),设置请求方法,post或者get<br/>
* getErrInfo(),获取错误信息<br/>
* setCertInfo(certFile, certPasswd),设置证书,双向https时需要使用<br/>
* setCaInfo(caFile), 设置CA,格式未pem,不设置则不检查<br/>
* setTimeOut(timeOut), 设置超时时间,单位秒<br/>
* getResponseCode(), 取返回的http状态码<br/>
* call(),真正调用接口<br/>
* getCharset()/setCharset(),字符集编码<br/>
*
* ========================================================================<br/>
*
*/
public class TenpayHttpClient {
private static final String USER_AGENT_VALUE = "Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)";
private static final String JKS_CA_FILENAME = "tenpay_cacert.jks";
private static final String JKS_CA_ALIAS = "tenpay";
private static final String JKS_CA_PASSWORD = "";
/** ca证书文件 */
private File caFile;
/** 证书文件 */
private File certFile;
/** 证书密码 */
private String certPasswd;
/** 请求内容,无论post和get,都用get方式提供 */
private String reqContent;
/** 应答内容 */
private String resContent;
/** 请求方法 */
private String method;
/** 错误信息 */
private String errInfo;
/** 超时时间,以秒为单位 */
private int timeOut;
/** http应答编码 */
private int responseCode;
/** 字符编码 */
private String charset;
private InputStream inputStream;
public TenpayHttpClient() {
this.caFile = null;
this.certFile = null;
this.certPasswd = "";
this.reqContent = "";
this.resContent = "";
this.method = "POST";
this.errInfo = "";
this.timeOut = 30;//30秒
this.responseCode = 0;
this.charset = "GBK";
this.inputStream = null;
}
/**
* 设置证书信息
* @param certFile 证书文件
* @param certPasswd 证书密码
*/
public void setCertInfo(File certFile, String certPasswd) {
this.certFile = certFile;
this.certPasswd = certPasswd;
}
/**
* 设置ca
* @param caFile
*/
public void setCaInfo(File caFile) {
this.caFile = caFile;
}
/**
* 设置请求内容
* @param reqContent 表求内容
*/
public void setReqContent(String reqContent) {
this.reqContent = reqContent;
}
/**
* 获取结果内容
* @return String
* @throws IOException
*/
public String getResContent() {
try {
this.doResponse();
} catch (IOException e) {
this.errInfo = e.getMessage();
//return "";
}
return this.resContent;
}
/**
* 设置请求方法post或者get
* @param method 请求方法post/get
*/
public void setMethod(String method) {
this.method = method;
}
/**
* 获取错误信息
* @return String
*/
public String getErrInfo() {
return this.errInfo;
}
/**
* 设置超时时间,以秒为单位
* @param timeOut 超时时间,以秒为单位
*/
public void setTimeOut(int timeOut) {
this.timeOut = timeOut;
}
/**
* 获取http状态码
* @return int
*/
public int getResponseCode() {
return this.responseCode;
}
/**
* 执行http调用。true:成功 false:失败
* @return boolean
*/
public boolean call() {
boolean isRet = false;
//http
if(null == this.caFile && null == this.certFile) {
try {
this.callHttp();
isRet = true;
} catch (IOException e) {
this.errInfo = e.getMessage();
}
return isRet;
}
//https
try {
this.callHttps();
isRet = true;
} catch (UnrecoverableKeyException e) {
this.errInfo = e.getMessage();
} catch (KeyManagementException e) {
this.errInfo = e.getMessage();
} catch (CertificateException e) {
this.errInfo = e.getMessage();
} catch (KeyStoreException e) {
this.errInfo = e.getMessage();
} catch (NoSuchAlgorithmException e) {
this.errInfo = e.getMessage();
} catch (IOException e) {
this.errInfo = e.getMessage();
}
return isRet;
}
protected void callHttp() throws IOException {
if("POST".equals(this.method.toUpperCase())) {
String url = HttpClientUtil.getURL(this.reqContent);
String queryString = HttpClientUtil.getQueryString(this.reqContent);
byte[] postData = queryString.getBytes(this.charset);
this.httpPostMethod(url, postData);
return ;
}
this.httpGetMethod(this.reqContent);
}
protected void callHttps() throws IOException, CertificateException,
KeyStoreException, NoSuchAlgorithmException,
UnrecoverableKeyException, KeyManagementException {
// ca目录
String caPath = this.caFile.getParent();
File jksCAFile = new File(caPath + "/"
+ TenpayHttpClient.JKS_CA_FILENAME);
if (!jksCAFile.isFile()) {
X509Certificate cert = (X509Certificate) HttpClientUtil
.getCertificate(this.caFile);
FileOutputStream out = new FileOutputStream(jksCAFile);
// store jks file
HttpClientUtil.storeCACert(cert, TenpayHttpClient.JKS_CA_ALIAS,
TenpayHttpClient.JKS_CA_PASSWORD, out);
out.close();
}
FileInputStream trustStream = new FileInputStream(jksCAFile);
FileInputStream keyStream = new FileInputStream(this.certFile);
SSLContext sslContext = HttpClientUtil.getSSLContext(trustStream,
TenpayHttpClient.JKS_CA_PASSWORD, keyStream, this.certPasswd);
//关闭流
keyStream.close();
trustStream.close();
if("POST".equals(this.method.toUpperCase())) {
String url = HttpClientUtil.getURL(this.reqContent);
String queryString = HttpClientUtil.getQueryString(this.reqContent);
byte[] postData = queryString.getBytes(this.charset);
this.httpsPostMethod(url, postData, sslContext);
return ;
}
this.httpsGetMethod(this.reqContent, sslContext);
}
public boolean callHttpPost(String url, String postdata) {
boolean flag = false;
byte[] postData;
try {
postData = postdata.getBytes(this.charset);
this.httpPostMethod(url, postData);
flag = true;
} catch (IOException e1) {
e1.printStackTrace();
}
return flag;
}
/**
* 以http post方式通信
* @param url
* @param postData
* @throws IOException
*/
protected void httpPostMethod(String url, byte[] postData) throws IOException {
HttpURLConnection conn = HttpClientUtil.getHttpURLConnection(url);
this.doPost(conn, postData);
}
/**
* 以http get方式通信
*
* @param url
* @throws IOException
*/
protected void httpGetMethod(String url) throws IOException {
HttpURLConnection httpConnection =
HttpClientUtil.getHttpURLConnection(url);
this.setHttpRequest(httpConnection);
httpConnection.setRequestMethod("GET");
this.responseCode = httpConnection.getResponseCode();
this.inputStream = httpConnection.getInputStream();
}
/**
* 以https get方式通信
* @param url
* @param sslContext
* @throws IOException
*/
protected void httpsGetMethod(String url, SSLContext sslContext)
throws IOException {
SSLSocketFactory sf = sslContext.getSocketFactory();
HttpsURLConnection conn = HttpClientUtil.getHttpsURLConnection(url);
conn.setSSLSocketFactory(sf);
this.doGet(conn);
}
protected void httpsPostMethod(String url, byte[] postData,
SSLContext sslContext) throws IOException {
SSLSocketFactory sf = sslContext.getSocketFactory();
HttpsURLConnection conn = HttpClientUtil.getHttpsURLConnection(url);
conn.setSSLSocketFactory(sf);
this.doPost(conn, postData);
}
/**
* 设置http请求默认属性
* @param httpConnection
*/
protected void setHttpRequest(HttpURLConnection httpConnection) {
//设置连接超时时间
httpConnection.setConnectTimeout(this.timeOut * 1000);
//User-Agent
httpConnection.setRequestProperty("User-Agent",
TenpayHttpClient.USER_AGENT_VALUE);
//不使用缓存
httpConnection.setUseCaches(false);
//允许输入输出
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
}
/**
* 处理应答
* @throws IOException
*/
protected void doResponse() throws IOException {
if(null == this.inputStream) {
return;
}
//获取应答内容
this.resContent=HttpClientUtil.InputStreamTOString(this.inputStream,this.charset);
//关闭输入流
this.inputStream.close();
}
/**
* post方式处理
* @param conn
* @param postData
* @throws IOException
*/
protected void doPost(HttpURLConnection conn, byte[] postData) throws IOException {
// 以post方式通信
conn.setRequestMethod("POST");
// 设置请求默认属性
this.setHttpRequest(conn);
// Content-Type
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedOutputStream out = new BufferedOutputStream(conn.getOutputStream());
final int len = 1024; // 1KB
HttpClientUtil.doOutput(out, postData, len);
// 关闭流
out.close();
// 获取响应返回状态码
this.responseCode = conn.getResponseCode();
// 获取应答输入流
this.inputStream = conn.getInputStream();
}
/**
* get方式处理
* @param conn
* @throws IOException
*/
protected void doGet(HttpURLConnection conn) throws IOException {
//以GET方式通信
conn.setRequestMethod("GET");
//设置请求默认属性
this.setHttpRequest(conn);
//获取响应返回状态码
this.responseCode = conn.getResponseCode();
//获取应答输入流
this.inputStream = conn.getInputStream();
}
}
相关推荐
"HFSS软件包下的圆锥(圆形)喇叭天线模型制作与参数调整:自主创造,实验验证,全流程教程指导",HFSS圆锥(圆形)喇叭天线 天线模型,自己做的,附带结果,可改参数,HFSS软件包 (有教程,具体到每一步,可以自己做出来) ,HFSS; 圆锥(圆形)喇叭天线; 模型自制; 参数可改; HFSS软件包; 教程详尽。,HFSS圆锥喇叭天线模型:可自定义参数与结果
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
"基于S7-200 PLC与组态王技术构建的智能化新能源汽车电池检测系统上位机软件平台",基于S7-200plc与组态王组态的新能源汽车电池检测系统上位机 ,S7-200plc;组态王组态;新能源汽车电池检测系统;上位机,"基于PLC与组态王的汽车电池检测上位机系统"
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
nodejs010-nodejs-docs-0.10.5-8.el6.centos.alt.x86_64.rpm
免费JAVA毕业设计 2024成品源码+论文+录屏+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
“基于Cadence Orcad的全面元器件数据库管理系统——全配版与基础版对比分析”,搭建使用Cadence Orcad CIS元器件数据库(默认为Access数据库,如需MySQL数据库需提前沟通),含orcad符号库,Allegro PCB库 —————————————————— 该元器件数据库种类丰富,大分类就有28种(全配版,含有很多如海思,全志,瑞芯微,TI,Xilinx等主流复杂IC的库信息),20种(基础版)。 ———————————————————— 全配版包含1000多种元器件属性信息汇总,都是已验证使用过的,可直接用于自己的电路设计。 全配版还附有大部分与元器件PCB封装已匹配好的的3D模型。 强烈建议原理图库及封装库基于数据库的方式来管理,好处主要有以下几点: 1. 易于管理,可通过数据库文件批量添加、更改或删除器件参数; 2. 减少原理图库的种类, 同类器件只需要新建一次原理图库, 例如不同阻值、精度的电阻; 3. 器件具有唯一性, 每个器件的参数都是唯一的; 4. 方便使用, 如使用 Link Database Part 功能,可以快速完成器件批量替,
1、文件内容:ptlib-devel-2.10.10-6.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/ptlib-devel-2.10.10-6.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、安装指导:私信博主,全程指导安装
西门子S7-1200+5轴伺服驱动系统的走工艺对象技术解析——采用脉冲输出驱动方式的控制方法及在全博途V15.1程序中的应用研究。,S7-1200+5轴伺服 走工艺对象 脉冲输出驱动方式 适用于西门子s7-1200+第三方伺服驱动器 全套博途v15.1程序 ,S7-1200;5轴伺服;走工艺对象;脉冲输出驱动方式;第三方伺服驱动器;博途v15.1程序,西门子S7-1200 5轴伺服系统控制程序
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
《四层三列堆垛式立体库控制系统:带解释的梯形图接线原理图及IO分配与组态画面详解》,4x3堆垛式立体库4层3列四层三列书架式立体库控制系统 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,立体库; 堆垛式; 控制系统; 梯形图; 接线图; 原理图; IO分配; 组态画面,"立体库控制系统原理图:四层三列堆垛式书架的IO分配与组态画面"
1、文件内容:pyOpenSSL-0.13.1-4.el7.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/pyOpenSSL-0.13.1-4.el7.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、安装指导:私信博主,全程指导安装
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
基于三菱PLC与MCGS技术的防盗门报警系统:梯形图接线图原理及IO分配、组态画面详解,基于三菱PLC和MCGS的防盗门报警器 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,三菱PLC; MCGS; 防盗门报警器; 梯形图接线图; IO分配; 组态画面,基于三菱PLC与MCGS的报警器系统:梯形图接线与组态画面详解
"COMSOL金膜表面等离子共振(SPR)分析:不同入射角下的共振角度观察",comsol金膜表面等离子共振SPR,不同入射角查看共振角度 ,关键词:comsol金膜表面;等离子共振(SPR);不同入射角;共振角度;分离度;角度调节;材料表面光;生物传感;互动现象;实时分析,"COMSOL研究金膜表面等离子共振: 角度变化影响共振角度"
1. 机器学习与深度学习 机器学习是人工智能的核心领域,旨在通过数据训练模型,使计算机能够从经验中学习和改进。监督学习、无监督学习和强化学习是其主要分支,广泛应用于图像识别、语音处理和预测分析等场景。深度学习作为机器学习的重要子领域,通过神经网络模拟人脑的工作机制,尤其在图像分类、自然语言处理和自动驾驶等领域取得了突破性进展。深度学习模型如卷积神经网络(CNN)和循环神经网络(RNN)已成为许多AI应用的基础。 2. 自然语言处理与计算机视觉 自然语言处理(NLP)使计算机能够理解、生成和处理人类语言,关键技术包括机器翻译、语音识别、情感分析和问答系统。例如,智能助手(如Siri、Alexa)和聊天机器人(如ChatGPT)都依赖于NLP技术。计算机视觉则让计算机能够“看懂”图像和视频,广泛应用于人脸识别、自动驾驶、医疗影像分析等领域。目标检测、图像分割和视频分析等技术正在推动安防、零售和制造业的智能化转型。 3. 强化学习与AI伦理 强化学习通过试错和奖励机制,训练智能体在复杂环境中做出最优决策,广泛应用于游戏AI(如AlphaGo)、机器人控制和资源调度等领域。与此同时,随着AI技术的快速发展,AI伦理和社会影响也成为重要研究方向。如何确保AI的公平性、透明性和隐私保护,以及应对AI对就业和社会结构的潜在影响,已成为学术界和产业界共同关注的焦点。AI的可持续发展离不开技术与伦理的平衡。
不同放牧策略对草原土壤性质的影响研究——基于机器学习.pdf
本资源提供一种基于Proteus仿真的纯硬件NE555呼吸灯设计方案,结合NE555定时器、三极管(如2N2222或8050)、电阻、电容等元件,完整实现LED的呼吸灯效果。内容包括: Proteus仿真模型搭建:电路原理图设计、虚拟示波器波形分析; 硬件实现步骤:元件选型、焊接调试、实测波形对比; 参数调优方法:通过仿真快速调整RC参数控制呼吸频率与渐变平滑度。 目标: 掌握Proteus中NE555电路仿真技巧; 理解硬件电路与仿真模型的匹配性; 学习从虚拟仿真到实物落地的全流程设计; 培养故障排查与参数优化能力。 核心功能: 仿真验证:在Proteus中模拟NE555的PWM输出及LED亮度渐变效果; 硬件实现:通过三极管驱动电路将仿真结果转化为实物呼吸灯; 双向调试:支持仿真与硬件实测数据对比,快速定位设计问题。 关键模块: NE555无稳态多谐振荡器(控制占空比渐变); Proteus虚拟示波器(观测PWM波形变化); 三极管电流放大电路(驱动高亮度LED)。 设计亮点 虚实结合:通过Proteus仿真降低硬件试错成本,提升学习效率。
,全c源程序太阳能并网逆变器全C源程序单相3kw5kw,板图原理图清单,可以直接打板验证,超好的生产光伏逆变器的技术方案,量产方案