MD5转义 和 调用http

调用http:

qingqibing版本:

import java.nio.charset.StandardCharsets;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @Description: http请求工具类
* @Author
* @Date 2023/8/21 15:25
* @Version 1.0
*/
public class HttpClientUtils{

private static Logger logger = LoggerFactory.getLogger(HttpClientUtils.class);
// 请求成功
public final static int OK = 200;

/**
* post请求
* @param url 请求url
* @param param 参数(使用&拼接好的参数)
* @return String 返回结果
*/
public static String sendPost(String url, String param) {
String result = "";
try {
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(
SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(scsf).build();
HttpPost httppost = new HttpPost(url);
httppost.addHeader("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
StringEntity entity = new StringEntity(param, ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8));
httppost.setEntity(entity);
//构建超时等配置信息
RequestConfig config = RequestConfig.custom().setConnectTimeout(1000) //连接超时时间
.setConnectionRequestTimeout(1000) //从连接池中取的连接的最长时间
.setSocketTimeout(10 * 1000) //数据传输的超时时间
.build();
httppost.setConfig(config);
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
HttpEntity resEntity = response.getEntity();
//回复接收
result = EntityUtils.toString(resEntity, "UTF-8");
}
} catch (Exception e) {
logger.error("请求融云失败\nurl:{}\nparam:{}\nmessage:{}", url, param, e.getMessage(), e);
}
return result;
}

}

使用::::::::::::::::::

转换md5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值