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

现在有哪些网站是做批发的推文关键词生成器

现在有哪些网站是做批发的,推文关键词生成器,有创意的宣传方式有哪些,网站开发设计怎么样HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议。 使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可&#x…

HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议。

使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可:

  1. 创建CloseableHttpClient对象。
  2. 创建请求方法的实例,并指定请求URL。如果需要发送GET请求,创建HttpGet对象;如果需要发送POST请求,创建HttpPost对象。
  3. 如果需要发送请求参数,可可调用setEntity(HttpEntity entity)方法来设置请求参数。setParams方法已过时(4.4.1版本)。
  4. 调用HttpGet、HttpPost对象的setHeader(String name, String value)方法设置header信息,或者调用setHeaders(Header[] headers)设置一组header信息。
  5. 调用CloseableHttpClient对象的execute(HttpUriRequest request)发送请求,该方法返回一个CloseableHttpResponse。
  6. 调用HttpResponse的getEntity()方法可获取HttpEntity对象,该对象包装了服务器的响应内容。程序可通过该对象获取服务器的响应内容;调用CloseableHttpResponse的getAllHeaders()、getHeaders(String name)等方法可获取服务器的响应头。
  7. 释放连接。无论执行方法是否成功,都必须释放连接

具体代码如下(HttpClient-4.4.1):

复制代码
/** * 简单httpclient实例* * @author arron* @date 2015年11月11日 下午6:36:49 * @version 1.0 */
public class SimpleHttpClientDemo {/*** 模拟请求* * @param url        资源地址* @param map    参数列表* @param encoding    编码* @return* @throws ParseException* @throws IOException*/public static String send(String url, Map<String,String> map,String encoding) throws ParseException, IOException{String body = "";//创建httpclient对象CloseableHttpClient client = HttpClients.createDefault();//创建post方式请求对象HttpPost httpPost = new HttpPost(url);//装填参数List<NameValuePair> nvps = new ArrayList<NameValuePair>();if(map!=null){for (Entry<String, String> entry : map.entrySet()) {nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));}}//设置参数到请求对象中httpPost.setEntity(new UrlEncodedFormEntity(nvps, encoding));System.out.println("请求地址:"+url);System.out.println("请求参数:"+nvps.toString());//设置header信息//指定报文头【Content-type】、【User-Agent】httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");//执行请求操作,并拿到结果(同步阻塞)CloseableHttpResponse response = client.execute(httpPost);//获取结果实体HttpEntity entity = response.getEntity();if (entity != null) {//按指定编码转换结果实体为String类型body = EntityUtils.toString(entity, encoding);}EntityUtils.consume(entity);//释放链接
        response.close();return body;}
}
复制代码

对于HTTPS的访问,采取绕过证书的策略:

复制代码
    /*** 绕过验证*     * @return* @throws NoSuchAlgorithmException * @throws KeyManagementException */public static SSLContext createIgnoreVerifySSL() throws NoSuchAlgorithmException, KeyManagementException {SSLContext sc = SSLContext.getInstance("SSLv3");// 实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法X509TrustManager trustManager = new X509TrustManager() {@Overridepublic void checkClientTrusted(java.security.cert.X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException {}@Overridepublic void checkServerTrusted(java.security.cert.X509Certificate[] paramArrayOfX509Certificate,String paramString) throws CertificateException {}@Overridepublic java.security.cert.X509Certificate[] getAcceptedIssuers() {return null;}};sc.init(null, new TrustManager[] { trustManager }, null);return sc;}
复制代码

然后修改原来的send方法:

复制代码
    /*** 模拟请求* * @param url        资源地址* @param map    参数列表* @param encoding    编码* @return* @throws NoSuchAlgorithmException * @throws KeyManagementException * @throws IOException * @throws ClientProtocolException */public static String send(String url, Map<String,String> map,String encoding) throws KeyManagementException, NoSuchAlgorithmException, ClientProtocolException, IOException {String body = "";//采用绕过验证的方式处理https请求SSLContext sslcontext = createIgnoreVerifySSL();// 设置协议http和https对应的处理socket链接工厂的对象Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext)).build();PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);HttpClients.custom().setConnectionManager(connManager);//创建自定义的httpclient对象CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build();
//        CloseableHttpClient client = HttpClients.createDefault();//创建post方式请求对象HttpPost httpPost = new HttpPost(url);//装填参数List<NameValuePair> nvps = new ArrayList<NameValuePair>();if(map!=null){for (Entry<String, String> entry : map.entrySet()) {nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));}}//设置参数到请求对象中httpPost.setEntity(new UrlEncodedFormEntity(nvps, encoding));System.out.println("请求地址:"+url);System.out.println("请求参数:"+nvps.toString());//设置header信息//指定报文头【Content-type】、【User-Agent】httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");//执行请求操作,并拿到结果(同步阻塞)CloseableHttpResponse response = client.execute(httpPost);//获取结果实体HttpEntity entity = response.getEntity();if (entity != null) {//按指定编码转换结果实体为String类型body = EntityUtils.toString(entity, encoding);}EntityUtils.consume(entity);//释放链接
        response.close();return body;}
复制代码

但是,如果是自己用jdk或者其他工具生成的证书,还是希望用其他方式认证自签名的证书,这篇文章就来分享一下如何设置信任自签名的证书。当然你也可以参考官网示例中。

要想信任自签名的证书,必须得知道密钥库的路径及密钥库的密码。然后加载到程序来才可以。具体代码如下:

复制代码
    /*** 设置信任自签名证书*     * @param keyStorePath        密钥库路径* @param keyStorepass        密钥库密码* @return*/public static SSLContext custom(String keyStorePath, String keyStorepass){SSLContext sc = null;FileInputStream instream = null;KeyStore trustStore = null;try {trustStore = KeyStore.getInstance(KeyStore.getDefaultType());instream = new FileInputStream(new File(keyStorePath));trustStore.load(instream, keyStorepass.toCharArray());// 相信自己的CA和所有自签名的证书sc = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();} catch (KeyStoreException | NoSuchAlgorithmException| CertificateException | IOException | KeyManagementException e) {e.printStackTrace();} finally {try {instream.close();} catch (IOException e) {}}return sc;}
复制代码

然后修改原来的send方法:

复制代码
    /*** 模拟请求* * @param url        资源地址* @param map    参数列表* @param encoding    编码* @return* @throws ParseException* @throws IOException* @throws KeyManagementException * @throws NoSuchAlgorithmException * @throws ClientProtocolException */public static String send(String url, Map<String,String> map,String encoding) throws ClientProtocolException, IOException {String body = "";//tomcat是我自己的密钥库的密码,你可以替换成自己的//如果密码为空,则用"nopassword"代替SSLContext sslcontext = custom("D:\\keys\\wsriakey", "tomcat");// 设置协议http和https对应的处理socket链接工厂的对象Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext)).build();PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);HttpClients.custom().setConnectionManager(connManager);//创建自定义的httpclient对象CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build();
//        CloseableHttpClient client = HttpClients.createDefault();//创建post方式请求对象HttpPost httpPost = new HttpPost(url);//装填参数List<NameValuePair> nvps = new ArrayList<NameValuePair>();if(map!=null){for (Entry<String, String> entry : map.entrySet()) {nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));}}//设置参数到请求对象中httpPost.setEntity(new UrlEncodedFormEntity(nvps, encoding));System.out.println("请求地址:"+url);System.out.println("请求参数:"+nvps.toString());//设置header信息//指定报文头【Content-type】、【User-Agent】httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");//执行请求操作,并拿到结果(同步阻塞)CloseableHttpResponse response = client.execute(httpPost);//获取结果实体HttpEntity entity = response.getEntity();if (entity != null) {//按指定编码转换结果实体为String类型body = EntityUtils.toString(entity, encoding);}EntityUtils.consume(entity);//释放链接
        response.close();return body;}
http://www.lbrq.cn/news/2603089.html

相关文章:

  • 网络推广服务合同模板短视频seo优化
  • php企业网站后台管理系统谷歌google下载
  • 网站建设公司不能备案吗石家庄seo
  • 个人 可以做网站备案吗软文范文200字
  • 海尔集团电子网站建设线上教育培训机构十大排名
  • 手机端做的优秀的网站设计娱乐热搜榜今日排名
  • 网站建设需要工作计划百度seo价格
  • 西安网站建设招聘优帮云排名优化
  • 淘宝做网站 评价话语关键词挖掘查询工具
  • 自己建私人网站做外贸不好做谈谈你对网络营销的看法
  • 全网网站建设优化活动策划公司
  • 工商注册核名查询系统官网免费使用seo软件
  • 创建网站的准备wordpress自助建站
  • 网站建设方案策划北京疫情最新新闻
  • 建行官网网站2023年又封城了
  • dw做的网站如何让别人看看西安网站维护公司
  • 公司做网站需要discuz论坛seo设置
  • 网站流量怎么做成品网站货源1688在线
  • 杭州微跑网站建设公司2345浏览器网址导航
  • 政法网站内容建设以图搜图
  • wordpress模块化布局西安关键词优化服务
  • 小伙反串做直播视频网站新闻 近期大事件
  • 做a小视频免费观看网站上海专业的seo公司
  • 陕西煤炭建设公司网站南宁seo费用服务
  • 商城类网站如何众筹成都网多多
  • 新零售平台公司有哪些南宁seo咨询
  • 济南小程序网站开发知名seo公司
  • wordpress的分类idseo优化多久能上排名
  • 企业网站建设教程视频亿速云
  • 建设银行舟山分行网站网络推广营销方案100例
  • MCP与Function Calling
  • 力扣热题100------21.合并两个有序链表
  • Linux—yum仓库及NFS网络共享服务
  • 思途Spring学习 0804
  • Go语言高并发价格监控系统设计
  • 【Bluetooth】【Transport层篇】第四章 基于基础UART的蓝牙硬件发送协议 UART H4 Transport详解