// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.sprucetec.datacenter.util; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.apache.http.Consts; import org.apache.http.HttpEntity; 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.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 org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HttpClientUtil { private static Logger log = LoggerFactory.getLogger(HttpClientUtil.class); public static final int DEFAULT_SOCKET_TIMEOUT = 5000; public static final int DEFAULT_CONNECT_TIMEOUT = 5000; public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 5000; private static CloseableHttpClient httpClient = HttpClients.createDefault(); public HttpClientUtil() { } public static String post(String url) { return post(url, (Map)null); } public static String post(String url, Map<String, String> param) { return post(url, param, RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).setConnectionRequestTimeout(5000).build()); } public static String post(String url, Map<String, String> param, RequestConfig requestConfig) { HttpPost httpPost = new HttpPost(url); httpPost.setConfig(requestConfig); CloseableHttpResponse response = null; Object responseString = null; if(null != param && param.size() > 0) { Set e = param.keySet(); ArrayList nvps = new ArrayList(); Iterator e1 = e.iterator(); while(e1.hasNext()) { String key = (String)e1.next(); nvps.add(new BasicNameValuePair(key, (String)param.get(key))); } try { log.info("set utf-8 form entity to httppost"); httpPost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8.name())); } catch (UnsupportedEncodingException var18) { throw new RuntimeException(var18.getMessage(), var18); } } try { response = httpClient.execute(httpPost); HttpEntity e2 = response.getEntity(); if(e2 != null) { String nvps1 = EntityUtils.toString(e2); return nvps1; } } catch (IOException var20) { throw new RuntimeException(var20.getMessage(), var20); } finally { try { if(response != null) { response.close(); } } catch (IOException var19) { log.warn("response is not closed"); throw new RuntimeException(var19.getMessage(), var19); } } return (String)responseString; } public static String postJson(String url) { return postJson(url, (String)null); } public static String postJson(String url, String jsonEntity) { return postJson(url, jsonEntity, RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).setConnectionRequestTimeout(5000).build()); } public static String postJson(String url, String jsonEntity, RequestConfig requestConfig) { HttpPost httpPost = new HttpPost(url); httpPost.setConfig(requestConfig); httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); httpPost.addHeader("Connection", "Keep-Alive"); httpPost.addHeader("user-agent", "MEICAI/WMC"); CloseableHttpResponse response = null; Object responseString = null; if(jsonEntity != null) { httpPost.setEntity(new StringEntity(jsonEntity, Consts.UTF_8.name())); } try { response = httpClient.execute(httpPost); HttpEntity e = response.getEntity(); if(e != null) { String var7 = EntityUtils.toString(e); return var7; } } catch (IOException var17) { throw new RuntimeException(var17.getMessage(), var17); } finally { try { if(response != null) { response.close(); } } catch (IOException var16) { log.warn("response is not closed"); throw new RuntimeException(var16.getMessage(), var16); } } return (String)responseString; } public static String get(String url) { String result = ""; try { HttpGet e = new HttpGet(url); CloseableHttpResponse httpResponse = null; httpResponse = httpClient.execute(e); try { HttpEntity entity = httpResponse.getEntity(); if(null != entity) { result = EntityUtils.toString(entity); } } finally { httpResponse.close(); } } catch (Exception var9) { var9.printStackTrace(); } return result; } }
相关推荐
SNAP计算哨兵二号的叶面积指数(LAI)
对于哨兵二号数据以及LANDSAT8数据,SNAP提供已经集成好的模块计算LAI。在Optical->Thematic Land Processing->Biopyhsical Processor目录下面。 对于经过Sen2Cor处理好的数据,需经过重采样才可进行计算。重采样工具在Raster->Geometric->Resampling。 如果选择Biopyhsical Processor S2_10m进行计算,需要将所有的波段都重采样为10米(哨兵二号的第二波段为10米,可据此波
HttpUtils工具类和post请求json参数传输
import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; import org.apache.http.client.ResponseHandler; import org.apache.http.client.entity.UrlEnc...
在Proteus中用80C51模拟4线SPI点亮OLED屏幕
在Proteus里用80C51模拟4线SPI控制OLED屏幕使其显示图案(汇编实现)。
用httpPost对JSON发送和接收的例子
HTTPPost发送JSON: private static final String APPLICATION_JSON = "application/json"; private static final String CONTENT_TYPE_TEXT_JSON = "text/json"; public static void httpPostWithJSO
基于PLC1200与CB1241的RS485从站Modbus Rtu通信实战指南
本文提供了一份详细的西门子S7-1200 PLC与CB1241 RS485通讯板实现Modbus RTU从站通信的实战指南。内容涵盖从硬件接线、博途软件组态、关键参数设置到程序调试与测试的全过程,重点解析了Modbus_Slave指令配置与数据块映射,帮助工程师快速掌握工业自动化系统中的数据采集与设备接入技术。
QDMA工程搭建/windows驱动编译与性能测试
请注意,根据您的目标操作系统,您可能需要在windows启动配置中启用测试签名的驱动程序,以便启用此驱动程序的安装。右键单击设备,选择更新驱动程序软件,然后选择构建的QDMA驱动程序的文件夹(通常为。创建一个新工程,在IP Catalog中搜索QDMA,双击创建qdma ip核。驱动程序安装安装驱动程序最简单的方法是通过Windows的“设备管理器”。如果系统提示未经验证的驱动程序发布者,请选择无论如何安装此驱动程序软件。本节主要介绍QDMA驱动在Windows系统的源文件、编译和安装过程。
封装HTTP POST信息的发送方法并返回JSON数据
/** * 封装HTTP POST信息的发送方法并返回JSON数据 * @author acer * */ public class HttpPostUtil { private static String[] sessionId = null; // 请求服务器端的URL public static String PATH = "http://192.168.2
Unity-RetargetPro3-动画插件试用
一个名气大于实战的插件。
常用工具类之HttpclientUtil
package com.chenfeng.ego.commons.util; import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.NameValuePair;
单片机:实现FFT快速傅里叶变换算法(附完整源码)
单片机:实现FFT快速傅里叶变换算法(附完整源码)
Altium Designer(AD)PCB拼版——两种方法教程
本文详细介绍了PCB拼版的设计要点与操作方法。主要内容包括:拼版目的(解决小尺寸夹持问题、提高利用率、降低成本)和三大连接方式(V-CUT、邮票孔、空心连接条)的特点与参数设置;工艺边设计规范(宽度、定位孔、Mark点等要求);拼版尺寸限制与常见错误检查;以及两种具体拼版操作方法(特殊粘贴和拼版阵列),并附有工艺边、定位孔、Mark点的绘制步骤示意图。同时提供了硬件工程师笔试面试相关资源链接。全文系统阐述了PCB拼版的核心技术和操作流程,为电子设计人员提供了实用指导。
HttpClientUtil工具类
HttpClientUtil.java import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.NameValuePair; import org.apach...
深入浅出讲解外部服务提供者 OAuth 2.0 帐户客户端创建与 ABAP 系统集成
本文详细介绍了在SAP ABAP平台配置OAuth 2.0客户端以安全调用外部Web服务的完整流程。主要内容包括:首先需要在外部服务提供者平台注册OAuth客户端,获取client ID和client secret;其次需特别注意重定向URI必须是公开可访问的地址;然后在ABAP系统中通过事务码OA2C_CONFIG配置OAuth客户端信息;最后阐述了常见的错误排查方法。文章强调了OAuth 2.0作为SAP系统与外部服务安全集成的标准协议,正确配置客户端是确保后续API调用安全可靠的关键前提。
HttpClientUtil工具包
需要的相关依赖: <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> &l...
怀旧版电脑GBC模拟器
再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。
复分析 阿尔福斯(Ahlfors) 第三版答案 英文
答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案
HttpClientUtil工具类的使用,亲测可用
前端时间领导要求弄个HttpClient 推送订单的例子 截图科普来自于百科 怎么做? 第一步 pom依赖 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.4</version> </dependency>
数学建模模型总结
这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!
HttpClientUtil——个人理解
是什么 模拟HTTP客户端,与服务器进行通讯 HttpClient 是 Apache Jakarta Common 下的子项目,用来提供高效、最新、功能丰富的 支持 HTTP 协议的客户端编程工具包,且支持 HTTP 协议最新的版本和建议。 http请求 由以下几种请求组成:GET, HEAD, POST, PUT, DELETE, TRACE and OPTIONS, 程序包中分别用
pscad IEEE标准系统搭建说明
pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。
httpclientutil java_基于 Httpclient 的封装 HttpClientUtil
import java.io.IOException;import java.io.UnsupportedEncodingException;import java.net.SocketTimeoutException;import java.nio.charset.Charset;import java.util.Base64;import java.util.List;import java....
跨域请求工具类HttpClientUtil
maven依赖 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </depende...
HttpClientUtil-工具类
HttpClientUtil-工具类 代码 package cn.hlbdx; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxExcep...
Java中HttpClientUtil工具类
HttpClientUtil工具类是java 调用第三方接口时需要使用到的,例如:在系统之间交互时获取参数。HttpClientUtil 包含get和post方法。 发送HttpPost或HttpGet请求一共三个步骤: 1、创建CloseableHttpClient对象,用于执行excute方法 2、创建HttpPost或者HttpGet请求对象 3、执行请求,判断返回状态,接收响应对象 package com.*.utils; import java.io.IOException; import j
RestTemplate编写的HttpClientUtil
import com.alibaba.fastjson.JSON; import org.springframework.http.*; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import java.util.Iterator; import java.util.Map; /** * @author
9418



被折叠的 条评论
为什么被折叠?



