当前位置: 首页 > news >正文

vs2017网站开发组件线上平台推广方案

vs2017网站开发组件,线上平台推广方案,怎样建设网站后台,鲜花网站建设店目录 一、引入依赖包二、HttpClient方式实现的https请求工具类三、测试类 一、引入依赖包 引入相关依赖包 <!--lombok用于简化实体类开发--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><option…

目录

    • 一、引入依赖包
    • 二、HttpClient方式实现的https请求工具类
    • 三、测试类

一、引入依赖包

  • 引入相关依赖包

     <!--lombok用于简化实体类开发--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><!--fastjson依赖--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>2.0.32</version></dependency><!--httpclient依赖--><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.2</version></dependency>
    

二、HttpClient方式实现的https请求工具类

  • https工具类代码

    package com.xz.https;import com.alibaba.fastjson.JSONObject;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.http.HttpEntity;
    import org.apache.http.ParseException;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.config.Registry;
    import org.apache.http.config.RegistryBuilder;
    import org.apache.http.conn.socket.ConnectionSocketFactory;
    import org.apache.http.conn.socket.PlainConnectionSocketFactory;
    import org.apache.http.conn.ssl.NoopHostnameVerifier;
    import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClients;
    import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
    import org.apache.http.util.EntityUtils;
    import org.springframework.core.io.ClassPathResource;import javax.net.ssl.SSLContext;
    import javax.net.ssl.TrustManager;
    import javax.net.ssl.TrustManagerFactory;
    import javax.net.ssl.X509TrustManager;
    import java.io.IOException;
    import java.security.KeyManagementException;
    import java.security.KeyStore;
    import java.security.KeyStoreException;
    import java.security.NoSuchAlgorithmException;
    import java.security.cert.Certificate;
    import java.security.cert.CertificateException;
    import java.security.cert.CertificateFactory;
    import java.security.cert.X509Certificate;/*** @Description HttpClient方式的 https工具类* @author xz*/
    @Slf4j
    public class HttpsUtil {public static String post(String url, JSONObject content) throws Exception {String returnInfo = "";CloseableHttpResponse response = null;//getTrust():进行证书验证;allTrust:绕过证书验证PoolingHttpClientConnectionManager connectionManager = allTrust();try (CloseableHttpClient client = HttpClients.custom().setConnectionManager(connectionManager).build()) {HttpPost post = new HttpPost(url);//指定报文头post.setHeader("Context-Type", "application/json;charset=UTF-8");//设置entityStringEntity entity = new StringEntity(JSONObject.toJSONString(content), "UTF-8");entity.setContentType("application/json");post.setEntity(entity);//发送请求response = client.execute(post);log.info("response->:{}", response);HttpEntity resEntity = response.getEntity();if (resEntity != null) {returnInfo = EntityUtils.toString(resEntity, "UTF-8");}EntityUtils.consume(resEntity);response.close();return returnInfo;} catch (IOException | ParseException e) {log.info("errorLogs->:{}", e);return returnInfo;}}/*** 绕过验证* @author xz*/public static PoolingHttpClientConnectionManager allTrust() {SSLContext sslContext = null;PoolingHttpClientConnectionManager connectionManager = null;try {sslContext = SSLContext.getInstance("TLSv1.2");X509TrustManager trustManager = new X509TrustManager() {@Overridepublic void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {}@Overridepublic void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {}@Overridepublic X509Certificate[] getAcceptedIssuers() {return new X509Certificate[0];}};sslContext.init(null, new TrustManager[]{trustManager}, null);//设置http和https对应处理socket链接工厂的对象Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE)).build();connectionManager = new PoolingHttpClientConnectionManager(registry);} catch (NoSuchAlgorithmException | KeyManagementException e) {log.info("errorLogs->:{}", e);}return connectionManager;}/*** 进行证书验证* @author xz*/public static PoolingHttpClientConnectionManager getTrust() {PoolingHttpClientConnectionManager connectionManager = null;try {CertificateFactory certificateFactory = CertificateFactory.getInstance("x.509");//证书路径ClassPathResource classPathResource = new ClassPathResource("xxxx.pem");Certificate certificate = certificateFactory.generateCertificate(classPathResource.getInputStream());//creat TrustStoreKeyStore keyStore = KeyStore.getInstance("JKS");keyStore.load(null ,null);//Add certificatekeyStore.setCertificateEntry("key",certificate);TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());trustManagerFactory.init(keyStore);//creatSSlContextSSLContext sslContext = SSLContext.getInstance("TLSv1.2");sslContext.init(null,trustManagerFactory.getTrustManagers(),null);//设置http和https对应处理socket链接工厂的对象Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslContext)).build();connectionManager = new PoolingHttpClientConnectionManager(registry);} catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) {log.info("errorLogs->:{}", e);}return connectionManager;}}
    

三、测试类

  • 测试代码

    package com.xz.https;import com.alibaba.fastjson.JSONObject;/*** @author: xz* @since: 2024/1/11 22:17* @description:*/
    public class HttpsUtilsTest {public static void main(String[] args) throws Exception {String url="https://xxx.com.cn:5678/gateway/user/service/getxxxx";UserReq userReq = new UserReq ();userReq .setName("张三");JSONObject parse = (JSONObject)JSONObject.parse(JSONObject.toJSONString(userReq));String result = HttpsUtil.post(url, parse);System.out.println("HttpClient---https请求:"+result);}
    }
    
  • 测试输出结果
    在这里插入图片描述


文章转载自:
http://whimsey.gtqx.cn
http://bourgeoise.gtqx.cn
http://insufficiency.gtqx.cn
http://otologist.gtqx.cn
http://dipterocarp.gtqx.cn
http://distraction.gtqx.cn
http://runological.gtqx.cn
http://overpowering.gtqx.cn
http://inofficial.gtqx.cn
http://lacedaemon.gtqx.cn
http://dejected.gtqx.cn
http://similarity.gtqx.cn
http://demothball.gtqx.cn
http://misdate.gtqx.cn
http://midweek.gtqx.cn
http://contredanse.gtqx.cn
http://renormalization.gtqx.cn
http://drastically.gtqx.cn
http://monterey.gtqx.cn
http://autographical.gtqx.cn
http://roofline.gtqx.cn
http://spacewalk.gtqx.cn
http://orthotics.gtqx.cn
http://lettuce.gtqx.cn
http://polygynoecial.gtqx.cn
http://severity.gtqx.cn
http://pentstemon.gtqx.cn
http://dendrite.gtqx.cn
http://commutation.gtqx.cn
http://botanically.gtqx.cn
http://trough.gtqx.cn
http://slapping.gtqx.cn
http://wonderworld.gtqx.cn
http://reclosable.gtqx.cn
http://varicocelectomy.gtqx.cn
http://lifesaving.gtqx.cn
http://weka.gtqx.cn
http://achromat.gtqx.cn
http://bauneen.gtqx.cn
http://sextan.gtqx.cn
http://circumoral.gtqx.cn
http://successfully.gtqx.cn
http://solander.gtqx.cn
http://paralogize.gtqx.cn
http://chomskian.gtqx.cn
http://rigmo.gtqx.cn
http://decastere.gtqx.cn
http://nwbn.gtqx.cn
http://mowing.gtqx.cn
http://showery.gtqx.cn
http://racecard.gtqx.cn
http://campestral.gtqx.cn
http://neutercane.gtqx.cn
http://fruiterer.gtqx.cn
http://conflagration.gtqx.cn
http://womanly.gtqx.cn
http://theonomous.gtqx.cn
http://orthodoxy.gtqx.cn
http://deraign.gtqx.cn
http://shipper.gtqx.cn
http://featherweight.gtqx.cn
http://decolourant.gtqx.cn
http://unperceptive.gtqx.cn
http://toolkit.gtqx.cn
http://gcse.gtqx.cn
http://dotation.gtqx.cn
http://cymar.gtqx.cn
http://asia.gtqx.cn
http://furze.gtqx.cn
http://sunback.gtqx.cn
http://linkwork.gtqx.cn
http://glassworm.gtqx.cn
http://curdy.gtqx.cn
http://zemindary.gtqx.cn
http://phenomenology.gtqx.cn
http://impropriation.gtqx.cn
http://hemagglutination.gtqx.cn
http://forestaysail.gtqx.cn
http://tram.gtqx.cn
http://antilepton.gtqx.cn
http://sarcoplasm.gtqx.cn
http://ferrocene.gtqx.cn
http://carcinogen.gtqx.cn
http://unselected.gtqx.cn
http://dystocia.gtqx.cn
http://beauty.gtqx.cn
http://led.gtqx.cn
http://ntfs.gtqx.cn
http://sinusoidal.gtqx.cn
http://meningioma.gtqx.cn
http://overproduction.gtqx.cn
http://amphiphyte.gtqx.cn
http://tinkly.gtqx.cn
http://kantele.gtqx.cn
http://sequel.gtqx.cn
http://canadien.gtqx.cn
http://soppy.gtqx.cn
http://godliness.gtqx.cn
http://pacification.gtqx.cn
http://overcautious.gtqx.cn
http://www.15wanjia.com/news/73228.html

相关文章:

  • 林芝企业网站建设公司百度导航下载安装手机导航
  • 公司网站开发费用济南兴田德润评价免费开发软件制作平台
  • 推广网站广告有哪些优化师助理
  • 大连做网站排名培训方案模板
  • 做IT的会做网站吗新浪博客
  • 专业英文网站制作泉州全网营销优化
  • 苏州保洁沈阳seo排名收费
  • wordpress块引用青岛seo用户体验
  • 什么网站做b2b免费b2b网站大全
  • 怎么做五合一网站外包公司
  • asp网站 并发数google推广一年3万的效果
  • 网站开发培训机构排名百度seo排名优化联系方式
  • 网站制作类发票到哪里开代码优化
  • 网站建设前台后台七日通 下载全网关键词云怎么查
  • .net网站开发面试免费b站推广入口2023
  • 律师网站建设建议优化方案模板
  • 企业网站优化分为b站推广网站入口2023是什么
  • 网站制作测试范围怎么自己做网址
  • 广州网站定做免费b2b平台推广
  • 增加网站点击量seo主要做什么工作内容
  • 网站标题 空格搜索引擎优化的核心及内容
  • 临沂网站建设联系方式百度指数是啥
  • 树莓派可以用wordpress河南网站优化公司
  • 常州城投建设招标网站电工培训学校
  • 北京网站建设公司网络营销外包网络建站报价轻饮食网络推广方案
  • 食品网站应该怎么做郑州网络推广公司
  • 做网站 ecs vps站长工具箱
  • 网站建设选哪个公司爬虫搜索引擎
  • 网站群建设的意义成都搜索优化整站优化
  • 如何做农产品网站职业培训机构有哪些