- 浏览: 18467 次
最新评论
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* 用于进行Https请求的HttpClient
* @ClassName: SSLClient
* @Description: TODO
* @author Devin <xxx>
* @date 2017年2月7日 下午1:42:07
*
*/
public class SSLClient extends DefaultHttpClient {
public SSLClient() throws Exception{
super();
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}
}
复制代码
2.创建一个利用HttpClient发送post请求的工具类
复制代码
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
/**
* 利用HttpClient进行post请求的工具类
* @ClassName: HttpClientUtil
* @Description: TODO
* @author Devin <xxx>
* @date 2017年2月7日 下午1:43:38
*
*/
public class HttpClientUtil {
@SuppressWarnings("resource")
public static String doPost(String url,String jsonstr,String charset){
HttpClient httpClient = null;
HttpPost httpPost = null;
String result = null;
try{
httpClient = new SSLClient();
httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json");
StringEntity se = new StringEntity(jsonstr);
se.setContentType("text/json");
se.setContentEncoding(new BasicHeader("Content-Type", "application/json"));
httpPost.setEntity(se);
HttpResponse response = httpClient.execute(httpPost);
if(response != null){
HttpEntity resEntity = response.getEntity();
if(resEntity != null){
result = EntityUtils.toString(resEntity,charset);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}
}
复制代码
3.测试代码
public static void main(String[] args){
String url = "https://192.168.1.101/xxx";
String jsonStr = "{xxx}";
String httpOrgCreateTestRtn = HttpClientUtil.doPost(url, jsonStr, "utf-8");
}
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* 用于进行Https请求的HttpClient
* @ClassName: SSLClient
* @Description: TODO
* @author Devin <xxx>
* @date 2017年2月7日 下午1:42:07
*
*/
public class SSLClient extends DefaultHttpClient {
public SSLClient() throws Exception{
super();
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}
}
复制代码
2.创建一个利用HttpClient发送post请求的工具类
复制代码
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
/**
* 利用HttpClient进行post请求的工具类
* @ClassName: HttpClientUtil
* @Description: TODO
* @author Devin <xxx>
* @date 2017年2月7日 下午1:43:38
*
*/
public class HttpClientUtil {
@SuppressWarnings("resource")
public static String doPost(String url,String jsonstr,String charset){
HttpClient httpClient = null;
HttpPost httpPost = null;
String result = null;
try{
httpClient = new SSLClient();
httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json");
StringEntity se = new StringEntity(jsonstr);
se.setContentType("text/json");
se.setContentEncoding(new BasicHeader("Content-Type", "application/json"));
httpPost.setEntity(se);
HttpResponse response = httpClient.execute(httpPost);
if(response != null){
HttpEntity resEntity = response.getEntity();
if(resEntity != null){
result = EntityUtils.toString(resEntity,charset);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}
}
复制代码
3.测试代码
public static void main(String[] args){
String url = "https://192.168.1.101/xxx";
String jsonStr = "{xxx}";
String httpOrgCreateTestRtn = HttpClientUtil.doPost(url, jsonStr, "utf-8");
}
发表评论
-
aaa
2018-03-26 17:23 01、前后端安全方案(防篡改、防重放、敏感信息加解密、防XSS攻 ... -
ssssss
2018-03-26 16:16 02015年年度计划 1、熟悉环境、架构、开发流程 2、业务模 ... -
golsing
2018-03-26 16:14 02015年年度计划 1、熟悉环境、架构、开发流程 2、业务模 ... -
ClientServiceRestTemplateImpl
2018-03-10 17:23 619package com.pingan.ff.btoam.dem ... -
ClientService
2018-03-10 17:34 482package com.pingan.ff.btoam.dem ... -
ClientConfig
2018-03-10 17:33 442package com.pingan.ff.btoam.dem ... -
responseDTO
2018-03-10 17:32 566package com.pingan.ff.btoam.dem ... -
配置项
2018-03-10 17:31 491client.connectTimeout=60000 cli ... -
HttpsClientRequestFactory
2018-03-08 20:48 1469package com.pingan.ff.btoam.dem ... -
HttpsTest
2018-03-08 20:23 862package com.pingan.ff.btoam.dem ... -
dfdfdf
2018-03-08 20:22 523<!--连接池管理 --> <bean ... -
sdds
2018-03-08 20:19 54package com.pingan.ff.esb.proxy ... -
测试一下
2017-08-23 13:50 585测试测试测试测试测试测试测试 -
面经面经
2017-03-29 19:13 556一、简历 简历里面需要 ... -
浅谈https\ssl\数字证书
2015-03-03 11:15 507http://www.cnblogs.com/P_Chou/a ... -
Java多线程总结之线程安全队列Queue
2015-01-07 15:20 862在Java多线程应用中,队列的使用率很高,多数生产消费模型的 ... -
面试问题
2015-01-07 14:45 586今天被架构师问了一连串的问题,估计问了有一个多小时 ... -
http长连接与短连接
2015-01-05 17:34 5691. HTTP协议与TCP/IP协议的关系 HTTP的长 ... -
ZooKeeper原理
2014-12-30 09:33 646ZooKeeper是一个分布式的,开放源码的分布式应用 ... -
diamond
2014-12-30 09:23 820大家好,今天开始为大家带来我们通用产品团队的产品 —— di ...
相关推荐
DDSD1352 单相电子式电能表使用说明书 DDSD1352 单相电子式电能表是一款用于计量低压网络的单相有功电能的电能表,同时可测量电压、电流、功率等电参量。该产品具有红外通讯功能,并可选配 RS485 通讯功能,方便...
DDSD1352-KC是一款先进的多功能电能表,主要应用于远程预付费系统中,为用户提供便捷的电力管理服务。这份"DDSD1352-KC使用说明书V1.1(远程预付费)"详细阐述了该电表的功能、安装、配置以及日常操作方法,旨在帮助...
ddsd.java
振中掌机程序符合645规约,用的是电力97规约,支持多费率,功能齐全
AFC-DDSD-采访 我已经上传了四个HTML文档和一个VBA电子表格,它们代表了我在NPS期间从事的编码/问题。 每个HTML文件都包含Jupyter Notebook或R Studio创建的代码,它们是作业的最终产品。 OA3801 Project-Wren....
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = nWidth; ddsd.dwHeight = nHeight; ``` **3. 切换模式** 为了支持模式的动态切换,还...
ddsd1.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH ddsd1.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN ddsd1.lWidth = 640 ddsd1.lHeight = 480 Set objDDOffSurf = objDD.CreateSurface(ddsd1) ``` - **...
Dim ddsd As DDSURFACEDESC2 Dim i As Long, lgCount As Long Set objDx = New DirectX7 '建立 DirectDraw 对象 Set objDraw = objDx.DirectDrawCreate("") '将DirectDraw对象支持的显示模式设置到...
DDSURFACEDESC ddsd1, ddsd2; ddsd1.dwSize = sizeof (DDSURFACEDESC); ddsd2.dwSize = sizeof(DDSURFACEDESC); lpDDSPic1->Lock(NULL, &ddsd1, DDLOCK_WAIT, NULL); lpDDSPic2->Lock(NULL, &ddsd2, DDLOCK_WAIT, ...
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // 这是离屏页面 ddsd.dwHeight = 480; // 高 ddsd.dwWidth = 640; // 宽 if (DD_OK != lpDD->...
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP; hr = dd7->CreateSurface(&ddsd, &primarySurface, NULL); ddsd.ddsCaps.dwCaps = DDSCAPS_...
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; // 创建一个离屏缓冲区 ddrval = lpDD->...
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface(&ddsd, &...
面向对象和基于数据驱动的软件开发相结合(OO_DDSD)是一种实用的原型化开发模型,旨在结合面向对象的编程理念和数据驱动的设计思想,以提高软件开发的效率和质量。该模型强调立足实例,以具体软件系统为开发出发点...
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface(&ddsd, &...
### 感应式电能表转矩矢量分析 #### 概述 感应式电能表因其结构简单、成本低、寿命长以及良好的负载特性,长期以来被供电和用电部门广泛采用作为电能计量工具。这类电能表的计量原理基于驱动转盘旋转的平均转矩,...
ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if (FAILED(pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL))) return r; return S_OK; } ``` ...
ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; hret = m_pDD->CreateSurface(&ddsd, &m_pDDSprimary_window, NULL...