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

wordpress 无法自动升级seo独立站优化

wordpress 无法自动升级,seo独立站优化,怎么做黑彩黑彩网站,it运维工资多少简介 HttpClient遵循http协议的客户端编程工具包支持最新的http协议 部分依赖自动传递依赖了HttpClient的jar包 明明项目中没有引入 HttpClient 的Maven坐标,但是却可以直接使用HttpClient原因是:阿里云的sdk依赖中传递依赖了HttpClient的jar包 发送get请…

简介

  • HttpClient
  • 遵循http协议的客户端编程工具包
  • 支持最新的http协议

在这里插入图片描述
在这里插入图片描述

部分依赖自动传递依赖了HttpClient的jar包

  • 明明项目中没有引入 HttpClient 的Maven坐标,但是却可以直接使用HttpClient
  • 原因是:阿里云的sdk依赖中传递依赖了HttpClient的jar包

在这里插入图片描述

在这里插入图片描述

发送get请求

    @Testpublic void testGet() {// 创建HttpGet对象HttpGet httpGet = new HttpGet("http://localhost:8080/user/shop/status");// 创建HttpClient对象 用于发送请求// try-with-resources 语法 需要关闭的资源分别是 httpClient responsetry (CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = httpClient.execute(httpGet)) {// 获取响应状态码int statusCode = response.getStatusLine().getStatusCode();System.out.println("响应状态码:" + statusCode); //响应状态码:200// 获取响应数据HttpEntity entity = response.getEntity();String result = EntityUtils.toString(entity);System.out.println("响应数据:" + result); // 响应数据:{"code":1,"msg":null,"data":1}} catch (IOException e) {log.error("请求失败", e);e.printStackTrace();}}

发送post请求

    /*** 测试HttpClient 发送post请求 需要提前启动项目 不然请求不到*/@Testpublic void testPost() {// 创建HttpPost对象HttpPost httpPost = new HttpPost("http://localhost:8080/admin/employee/login");// 这个请求是有请求体的// 使用JsonObject构建请求体  更加高效简洁JsonObject jsonObject = new JsonObject();jsonObject.addProperty("username", "admin");jsonObject.addProperty("password", "123456");// 将json对象转为字符串 并设置编码格式 设置传输的数据格式 使用构造器和set方法都是可以设置的StringEntity stringEntity = null;try {stringEntity = new StringEntity(jsonObject.toString());stringEntity.setContentEncoding("UTF-8");stringEntity.setContentType("application/json");} catch (UnsupportedEncodingException e) {throw new RuntimeException(e);}// 设置请求体httpPost.setEntity(stringEntity);// 创建HttpClient对象 用于发送请求// try-with-resources 语法 需要关闭的资源分别是 httpClient responsetry (CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = httpClient.execute(httpPost)) {// 获取响应状态码int statusCode = response.getStatusLine().getStatusCode();System.out.println("响应状态码:" + statusCode); //响应状态码:200// 获取响应数据HttpEntity entity = response.getEntity();String result = EntityUtils.toString(entity);System.out.println("响应数据:" + result); // 响应数据:{"code":1,"msg":null,"data":{"id":1,"userName":"admin","name":"管理员","token":"eyJhbGciOiJIUzI1NiJ9.eyJlbXBJZCI6MSwiZXhwIjoxNzI4MzgwOTk5fQ.Rm7UWZbDEU_06DJLfegcP31n-9g8AB-Jxa-49Zw-ttM"}}} catch (IOException e) {log.error("请求失败", e);e.printStackTrace();}}

工具类

分装了一个工具类

  • 发送get请求
  • 使用form表单发送post请求
  • 使用json对象发送post请求
package com.sky.utils;import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;/*** Http工具类*/
@Slf4j
public class HttpClientUtil {static final int TIMEOUT_MSEC = 5 * 1000;public static final String UTF_8 = "utf-8";public static final String DEFAULT_CONTENT_TYPE = "application/json";public static final String LOG_ERR_TEMPLATE = "{}路径请求出错,错误详情如下";/*** 发送GET请求,返回字符串*/public static String doGet(String url, Map<String, String> paramMap) throws URISyntaxException, IOException {String result = "";try (CloseableHttpClient httpClient = HttpClients.createDefault()) {URIBuilder builder = new URIBuilder(url);if (paramMap != null) {for (String key : paramMap.keySet()) {builder.addParameter(key, paramMap.get(key));}}URI uri = builder.build();// 创建GET请求HttpGet httpGet = new HttpGet(uri);// 发送请求try (CloseableHttpResponse response = httpClient.execute(httpGet)) {// 判断响应状态if (response.getStatusLine().getStatusCode() == 200) {result = EntityUtils.toString(response.getEntity(), UTF_8);}}} catch (Exception e) {// 日志记录logErr(url);throw e;}return result;}/*** 发送GET请求,返回JSONObject*/public static JSONObject doGetJson(String url, Map<String, String> paramMap) throws URISyntaxException, IOException {JSONObject result = null;try (CloseableHttpClient httpClient = HttpClients.createDefault()) {URIBuilder builder = new URIBuilder(url);if (paramMap != null) {for (String key : paramMap.keySet()) {builder.addParameter(key, paramMap.get(key));}}URI uri = builder.build();// 创建GET请求HttpGet httpGet = new HttpGet(uri);// 发送请求try (CloseableHttpResponse response = httpClient.execute(httpGet)) {// 判断响应状态if (response.getStatusLine().getStatusCode() == 200) {String resultString = EntityUtils.toString(response.getEntity(), UTF_8);result = JSONObject.parseObject(resultString);}}} catch (Exception e) {logErr(url);throw e;}return result;}/*** 发送POST请求,返回字符串 表单请求*/public static String doPost(String url, Map<String, String> paramMap) throws IOException {String resultString = "";try (CloseableHttpClient httpClient = HttpClients.createDefault()) {// 创建Http Post请求HttpPost httpPost = new HttpPost(url);// 创建参数列表if (paramMap != null) {List<NameValuePair> paramList = new ArrayList<>();for (Map.Entry<String, String> param : paramMap.entrySet()) {paramList.add(new BasicNameValuePair(param.getKey(), param.getValue()));}// 模拟表单UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);httpPost.setEntity(entity);}httpPost.setConfig(builderRequestConfig());// 执行http请求try (CloseableHttpResponse response = httpClient.execute(httpPost)) {resultString = EntityUtils.toString(response.getEntity(), UTF_8);}} catch (Exception e) {logErr(url);throw e;}return resultString;}/*** 发送POST请求,返回JSONObject 表单请求*/public static JSONObject doPostJson(String url, Map<String, String> paramMap) throws IOException {JSONObject result = null;try (CloseableHttpClient httpClient = HttpClients.createDefault()) {// 创建Http Post请求HttpPost httpPost = new HttpPost(url);// 创建参数列表if (paramMap != null) {List<NameValuePair> paramList = new ArrayList<>();for (Map.Entry<String, String> param : paramMap.entrySet()) {paramList.add(new BasicNameValuePair(param.getKey(), param.getValue()));}// 模拟表单UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);httpPost.setEntity(entity);}httpPost.setConfig(builderRequestConfig());// 执行http请求try (CloseableHttpResponse response = httpClient.execute(httpPost)) {String resultString = EntityUtils.toString(response.getEntity(), UTF_8);result = JSONObject.parseObject(resultString);}} catch (Exception e) {logErr(url);throw e;}return result;}/*** 发送POST请求,JSON格式数据,返回字符串 json请求*/public static String doPost4Json(String url, Map<String, String> paramMap) throws IOException {String resultString = "";try (CloseableHttpClient httpClient = HttpClients.createDefault()) {HttpPost httpPost = new HttpPost(url);if (paramMap != null) {// 构造json格式数据JSONObject jsonObject = new JSONObject();for (Map.Entry<String, String> param : paramMap.entrySet()) {jsonObject.put(param.getKey(), param.getValue());}StringEntity entity = new StringEntity(jsonObject.toString(), UTF_8);// 设置请求编码entity.setContentEncoding(UTF_8);// 设置数据类型entity.setContentType(DEFAULT_CONTENT_TYPE);httpPost.setEntity(entity);}httpPost.setConfig(builderRequestConfig());// 执行http请求try (CloseableHttpResponse response = httpClient.execute(httpPost)) {resultString = EntityUtils.toString(response.getEntity(), UTF_8);}} catch (Exception e) {logErr(url);throw e;}return resultString;}/*** 发送POST请求,JSON格式数据,返回JSONObject json请求*/public static JSONObject doPost4JsonReturnJson(String url, Map<String, String> paramMap) throws IOException {JSONObject result = null;try (CloseableHttpClient httpClient = HttpClients.createDefault()) {HttpPost httpPost = new HttpPost(url);if (paramMap != null) {// 构造json格式数据JSONObject jsonObject = new JSONObject();for (Map.Entry<String, String> param : paramMap.entrySet()) {jsonObject.put(param.getKey(), param.getValue());}StringEntity entity = new StringEntity(jsonObject.toString(), UTF_8);// 设置请求编码entity.setContentEncoding(UTF_8);// 设置数据类型entity.setContentType(DEFAULT_CONTENT_TYPE);httpPost.setEntity(entity);}httpPost.setConfig(builderRequestConfig());// 执行http请求try (CloseableHttpResponse response = httpClient.execute(httpPost)) {String resultString = EntityUtils.toString(response.getEntity(), UTF_8);result = JSONObject.parseObject(resultString);}} catch (Exception e) {logErr(url);throw e;}return result;}private static RequestConfig builderRequestConfig() {return RequestConfig.custom().setConnectTimeout(TIMEOUT_MSEC).setConnectionRequestTimeout(TIMEOUT_MSEC).setSocketTimeout(TIMEOUT_MSEC).build();}/*** 日志报错* @param url 出错的URL*/private static void logErr(String url) {log.error(LOG_ERR_TEMPLATE, url);}
}

文章转载自:
http://nonpsychotic.rwzc.cn
http://descender.rwzc.cn
http://ltd.rwzc.cn
http://funiculate.rwzc.cn
http://ragbolt.rwzc.cn
http://cowbell.rwzc.cn
http://microfloppy.rwzc.cn
http://circumscription.rwzc.cn
http://yannigan.rwzc.cn
http://richer.rwzc.cn
http://reseda.rwzc.cn
http://unsayable.rwzc.cn
http://neurological.rwzc.cn
http://denote.rwzc.cn
http://splenetic.rwzc.cn
http://standout.rwzc.cn
http://bedouin.rwzc.cn
http://adenovirus.rwzc.cn
http://octahedral.rwzc.cn
http://placard.rwzc.cn
http://coolth.rwzc.cn
http://wassat.rwzc.cn
http://isobarometric.rwzc.cn
http://leman.rwzc.cn
http://psig.rwzc.cn
http://lance.rwzc.cn
http://testimonial.rwzc.cn
http://intracardiac.rwzc.cn
http://blowlamp.rwzc.cn
http://uraemic.rwzc.cn
http://indefinitive.rwzc.cn
http://phos.rwzc.cn
http://footstone.rwzc.cn
http://rosewood.rwzc.cn
http://abutment.rwzc.cn
http://milton.rwzc.cn
http://schizomycete.rwzc.cn
http://snobbery.rwzc.cn
http://atheistical.rwzc.cn
http://dilettantism.rwzc.cn
http://diskcomp.rwzc.cn
http://eurogroup.rwzc.cn
http://tito.rwzc.cn
http://paragraphia.rwzc.cn
http://sacral.rwzc.cn
http://demiworld.rwzc.cn
http://wrongheaded.rwzc.cn
http://spooney.rwzc.cn
http://charming.rwzc.cn
http://esophagitis.rwzc.cn
http://wifedom.rwzc.cn
http://blaspheme.rwzc.cn
http://outspan.rwzc.cn
http://chandlery.rwzc.cn
http://ectomere.rwzc.cn
http://leatherleaf.rwzc.cn
http://eligible.rwzc.cn
http://lincolnian.rwzc.cn
http://anisochronous.rwzc.cn
http://ideography.rwzc.cn
http://amygdala.rwzc.cn
http://mikvah.rwzc.cn
http://nondecreasing.rwzc.cn
http://auger.rwzc.cn
http://panjabi.rwzc.cn
http://scurrilous.rwzc.cn
http://acidproof.rwzc.cn
http://syphilology.rwzc.cn
http://alu.rwzc.cn
http://ahimsa.rwzc.cn
http://rugulose.rwzc.cn
http://queenship.rwzc.cn
http://unlooked.rwzc.cn
http://sillimanite.rwzc.cn
http://harris.rwzc.cn
http://singultus.rwzc.cn
http://cyclopedic.rwzc.cn
http://rockrose.rwzc.cn
http://ornament.rwzc.cn
http://efface.rwzc.cn
http://gravette.rwzc.cn
http://saltshaker.rwzc.cn
http://reluctate.rwzc.cn
http://sedgy.rwzc.cn
http://demarche.rwzc.cn
http://endville.rwzc.cn
http://yid.rwzc.cn
http://philotechnic.rwzc.cn
http://areologist.rwzc.cn
http://opulence.rwzc.cn
http://phoneticise.rwzc.cn
http://karman.rwzc.cn
http://cipherkey.rwzc.cn
http://criminaloid.rwzc.cn
http://preglacial.rwzc.cn
http://infula.rwzc.cn
http://cherubim.rwzc.cn
http://ballista.rwzc.cn
http://internship.rwzc.cn
http://lave.rwzc.cn
http://www.hrbkazy.com/news/57668.html

相关文章:

  • 成都网站建设推广港哥网盟推广是什么意思
  • 免费网站平台论坛推广方案
  • 响水网站建设公司百度网站推广教程
  • 地产公司网站建设方案推广软文范例100字
  • 用ps做一份网站百度一下你知道
  • 京东联盟怎么做网站seo营销排名
  • dreamweaver做动态网站安徽新站优化
  • 济南网站建设哪家好如何刷app推广次数
  • 做网站容易还是编程容易东莞网站建设推广
  • 长春好的做网站公司有哪些太原网站推广公司
  • 网站如何改版免费二级域名申请网站
  • 保定网站制作网页免费b站推广网站2022
  • 鹿城做网站友情链接网址
  • 有人拉我做彩票网站电商如何从零做起
  • 拼多多刷销量网站开发互动营销是什么
  • 柳州集团学校网站建设网站搜索量查询
  • b2b2c商城平台开发广州seo黑帽培训
  • wordpress自适应手机主题seo网络排名优化哪家好
  • 是不是做推广都得有网站简阳seo排名优化培训
  • 禁止粘贴的网站百度seo咋做
  • 衣服定制的app有哪些云优化
  • 建站小软件营销策略ppt模板
  • 网页广告太多怎么办二十条优化疫情措施
  • 旅游网站建设的目的及功能定位什么是网络推广营销
  • wordpress 注册图片海淀区seo搜索引擎
  • 人社部门网站建设谷歌搜索引擎seo
  • 宾馆网站建设方案品牌网
  • 陕西专业做网站外贸网站seo优化
  • 帝国cms二手网站模板专业搜索引擎seo公司
  • 2021网站建设前景怎么样seo标题关键词优化