- 浏览: 780740 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (480)
- Spring (12)
- Hibernate (8)
- Struts2 (4)
- Java 基础-JDK-类-接口-URI-专题研究 (27)
- 线程、线程池、多线程高并发高可用、Socket通信 (15)
- Oracle数据库 (20)
- 一般-前端js-html-其它 (25)
- JYSK-互联网金融、金融科技、支付、公司、新闻等等 (8)
- Ajax-jQuery开源框架 (7)
- Json-轻量级的数据交换格式 (14)
- JavaScript (15)
- Jsp、Servlet、Servlet+JSP+JavaBean开发模式(MVC) (18)
- Html-JavaScript-前端-调用接口 (12)
- Sql Server 2005 (6)
- 正则表达式 (2)
- Java tools (18)
- 加签与验签、加密与解密 (3)
- Ajax技术核心-xmlHttpRequest(简称XHR) (6)
- xml-数据交换格式 (3)
- 信息采集 (1)
- Http - Https - HttpClient - httpCore-SSL-TLS (10)
- HtmlParser (2)
- 标签库 (1)
- SMS (2)
- jxl-导入导出 (4)
- poi-导入导出 (2)
- 定时器Timer+Quartz (6)
- 工作流引擎JBPM3.2.3 (4)
- 工作流引擎JBPM4 (0)
- 数据源-JNDI (0)
- tomcat、weblogic等应用服务器 (6)
- 工作流引擎jbpm5 (1)
- 搜索引擎Lucene (1)
- ant (1)
- 大数据-HBase (2)
- bigtable (0)
- 数据库设计 (4)
- jquery tab (0)
- mybatis (5)
- jquery ui 1.10.3 (5)
- Jboss7 (1)
- 规则引擎drools (0)
- 工作流引擎Activiti5 (0)
- 数据库-用户自定义函数 (0)
- 数据库-存储过程 (2)
- 数据库-视图 (0)
- 数据库-触发器 (0)
- 数据库-sql (2)
- highcharts-图表工具 (1)
- sql server 2008 (6)
- 诗词-工作室 (2)
- 数据割接 (1)
- GIS-地理信息系统 (2)
- RS-遥感技术 (1)
- GPS-全球定位系统 (1)
- java整合flex_RIA开发 (3)
- C#编程语言 (5)
- webservice_axis2_cxf_soap_wsdl (2)
- sql语句 (3)
- Flex_WebService_GIS (25)
- PHP编程语言 (0)
- ExtJS4.2 (1)
- Spring mvc (5)
- EasyUI1.4.2 (16)
- 日期时间工具类 (4)
- 随机数 (1)
- Arcgis api for js (0)
- Mysql数据库 (9)
- 移动互联网 java html5/flash socket netty (0)
- API接口 (1)
- AndroidStudio (0)
- Git (2)
- Maven (5)
- IDEA (0)
- 大数据-Hadoop (2)
- JPA (0)
- Spring boot (4)
- JSF (0)
- nginx_lua_module_redis (2)
- Activiti (1)
- bootstrap (1)
- AngularJS (10)
- 数据库-索引 (1)
- Linux及其连接工具SSH (4)
- java日志管理 (2)
- islider滑动控件 (1)
- jquery (1)
- 异常处理Exception (1)
- 秒杀与类秒杀系统 (1)
- 连接数据库、数据库连接池 (4)
- 数据库-临时表 (1)
- 软件设计模式-单例、多例、代理、工厂、观察者 (3)
- 集合框架 (5)
- 人工智能--Artificial intelligence、神经网络算法、机器学习 (1)
- 分布式应用 (1)
- SOA服务-Dubbo框架-Thrift框架 (2)
- Zookeeper分布式服务框架 (2)
- intellij idea (1)
- python编程语言 (0)
- 消息队列_MQ (0)
- 消息队列_RabbitMQ (2)
- 消息队列_ActiveMQ (1)
- 消息队列_Kafka (2)
- 缓存_Redis (4)
- 缓存_Memcache (0)
- 缓存_Ehcache (0)
- ivy-ivyde (1)
- google-protocol buffers (1)
- 正向代理-正向代理服务器 (1)
- 反向代理-反向代理服务器 (1)
- JVM内存模型 (0)
- Thunder框架 (1)
- NIO-非阻塞式IO (0)
- 软件测试、性能测试 (1)
- 序列化、Serializable接口、Externalizable接口 (3)
- 线程池-ExecutorService-ThreadPoolExecutor (1)
- web.xml (1)
- java开发-java工具-实用工具网站 (6)
- 医疗 (1)
- Filter-过滤器 (2)
- Unicode码-双字节字符编码 (1)
- OpenResty (1)
- 计算机网络 (1)
- eclipse_myeclipse_intellij idea (3)
- Enum (1)
- 大数据--Big Data (1)
- 云计算--Cloud computing (1)
- Elastic-Job (1)
- Redis (2)
- 文件流-IO操作 (6)
- 计算机基础知识 (1)
- Hessian-二进制RPC协议 (1)
- String类 (3)
- BigDecimal类 (1)
- java重要接口 (1)
- ReactJS (1)
- 跨域问题 (0)
- Map (1)
- 注解 (1)
- ASCII码-单字节字符编码 (1)
- 微服务、微服务架构 (2)
- RPC协议、RPC服务、RPC框架 (0)
- java反射 (1)
- java项目之classpath (1)
- 经典算法-树 (1)
- listener-监听器 (1)
- Interceptor-拦截器 (1)
- pojo javabean (2)
- 计算机科学与技术-进阶 (1)
- 代码规范与文档编写 (1)
- UML-统一建模语言 (1)
- 对接微信、支付宝 (3)
- 压力测试 (1)
- 办公软件-Excel (1)
- 办公软件-PPT (0)
- UTF8、GBK编码 (1)
- 微服务架构:Spring Cloud架构-Dubbo架构 (6)
- Nginx (1)
- 点滴业务 (1)
- form表单-json数据-转换与接口调用 (1)
- Junit单元测试 (1)
- 大数据-Spark (1)
- 大数据-Storm (1)
- 数据库事务-Spring事务 (0)
- elasticsearch (1)
- windows (1)
最新评论
httpclient中的httppost、httpget----调用接口以及main方法直接调用API接口
引用参考:
--HttpClient总结一之基本使用
https://www.cnblogs.com/LuckyBao/p/6096145.html
--Java HttpClient使用小结
http://blog.csdn.net/bhq2010/article/details/9210007
--HttpClient的HttpGet和HttpPost工具类
http://blog.csdn.net/william_wei007/article/details/75330686
--通过 GET方式传值的时候,+号会被浏览器处理为空,需要转换为%2b
https://blog.csdn.net/after_you/article/details/77834228
Http请求响应信息
--HttpClient总结一之基本使用
https://www.cnblogs.com/LuckyBao/p/6096145.html
--Java HttpClient使用小结
http://blog.csdn.net/bhq2010/article/details/9210007
--HttpClient的HttpGet和HttpPost工具类
http://blog.csdn.net/william_wei007/article/details/75330686
--通过 GET方式传值的时候,+号会被浏览器处理为空,需要转换为%2b
https://blog.csdn.net/after_you/article/details/77834228
public class salaryPay { public static String url = "http://192.168.5.138:8033/";// test环境 private static String check = url + "newApi/card/salaryPay"; public static void main(String[] args) { HttpUtil.httpPost(check, null, new HttpCallBackListener() { @Override public void success(int response, Header[] headers, String result) { System.out.print(response + "响应数据----" + result); } @Override public void failure(int response) { System.err.print(response); } }); } }
/** * HttpClient */ private static final HttpClient client= getHttpClientInstance(); /** * 单例 使Httpclient支持https */ private static HttpClient getHttpClientInstance() { X509TrustManager x509mgr = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] xcs, String string) { } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; SSLContext sslContext = null; try { sslContext = SSLContext.getInstance(SSLConnectionSocketFactory.SSL); sslContext.init(null, new TrustManager[] { x509mgr }, null); } catch (NoSuchAlgorithmException | KeyManagementException e) { logger.error("error to init httpclient", e); } SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setMaxTotal(200);// 客户端总并行链接最大数 connManager.setDefaultMaxPerRoute(20); // 每个主机的最大并行链接数 HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); httpClientBuilder.setConnectionManager(connManager); httpClientBuilder.setSSLSocketFactory(sslsf); return httpClientBuilder.build(); } /** * HttpEntity转化返回为byte数组 * */ private static byte[] doChangeEntity2Bytes(HttpEntity entity) throws Exception { InputStream inputStream = null; try { if (entity == null || entity.getContent() == null) { throw new RuntimeException("Response Entity Is null"); } inputStream = entity.getContent(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = inputStream.read(buffer)) != -1) { out.write(buffer, 0, len); } out.flush(); return out.toByteArray(); } finally { if (inputStream != null) { inputStream.close(); } } } /** * HttpPost */ private static byte[] doHttpPostFun(String address, HttpEntity paramEntity, RequestConfig config) throws Exception { HttpPost post = new HttpPost(address); try { if (paramEntity != null) { post.setEntity(paramEntity); } post.setConfig(config); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { int code = response.getStatusLine().getStatusCode(); throw new RuntimeException("HttpPost Request Access Fail Return Code(" + code + ")"); } HttpEntity entity = response.getEntity(); if (entity == null) { throw new RuntimeException("HttpPost Request Access Fail Response Entity Is null"); } return doChangeEntity2Bytes(entity); } finally { if (post != null) { post.releaseConnection(); } } } /** * HttpGet */ private static byte[] doHttpGetFun(String address, RequestConfig config) throws Exception { HttpGet get = new HttpGet(address); try { get.setConfig(config); HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { int code = response.getStatusLine().getStatusCode(); throw new RuntimeException("HttpGet Access Fail , Return Code(" + code + ")"); } response.getEntity().getContent(); return doChangeEntity2Bytes(response.getEntity()); } finally { if (get != null) { get.releaseConnection(); } } }
private static final Logger logger = LoggerFactory.getLogger(ClassDemo.class); private static final String type = "/demo/mat/{0}/{1}/{2}/Json"; @Value("${com.demo.check.url}") private String baseUrl; public EntityResponse checkCardNoAndBank(EntityRequest entityRequest) throws Exception { try { String url = baseUrl + type; logger.info("-->打印日志"url); String completeUrl = MessageFormat.format(url, URLEncoder.encode(entityRequest.getName(),"utf-8"),entityRequest.getNo(),URLEncoder.encode(entityRequest.getType(),"utf-8")); String json = HttpClientHelper.getDataByGetMethod(completeUrl); logger.info("json Resposne >>>" + json); return GsonUtils.convertObj(json, EntityResponse.class); }catch (Exception e){ e.printStackTrace(); return null; } }
private boolean doPostFun(Map<String, String> paramsMap){ boolean rtnFlag=false; if(null!=paramsMap&¶msMap.isEmpty()==false){ try { /** * 形式1:Content-Type: text/plain; charset=UTF-8 */ String paramJson = GsonUtils.toJson(paramsMap); HttpEntity paramEntity = new StringEntity(paramJson.toString(),"UTF-8"); respJson = HttpClientUtils.getMethodPostResponse(url, paramEntity); /** * 形式2:Content-Type: application/json;charset=utf-8 */ String paramJson = GsonUtils.toJson(paramsMap); StringEntity entity = new StringEntity(paramJson,"UTF-8"); entity.setContentType("application/json"); // //post请求 respJson = HttpClientUtils.getMethodPostResponse(url, entity); logger.info("正常->" + respJson); } catch (Exception e) { e.printStackTrace(); logger.info("异常->" + e.getMessage()); } ResponseDto result= GsonUtils.convertObj(respJson, ResponseDto.class); if (null!=result&&StringUtils.isNotBlank(result.getStatus())&&"1".equals(result.getStatus())) { //成功 logger.info("成功->cid="+paramsMap.get("cid")); rtnFlag=true; }else{ //失败 logger.info("失败->cid="+paramsMap.get("cid")); } } return rtnFlag; }
Http请求响应信息
================================================================= 【请求信息】 ID: 1091 Address: http://.../Info Encoding: UTF-8 Http-Method: POST Content-Type: application/json;charset=UTF-8 Headers: { Accept=[application/json, text/plain, */*], accept-encoding=[gzip, deflate], accept-language=[zh-CN,en-US;q=0.8], connection=[close], Content-Length=[399], content-type=[application/json;charset=UTF-8], cookie=[_fmdata=4500B47041D0BFFC9DD4B420764A5B0070658214442367DF663AD941615413F75382049B327144F56CE5D4438C8A6D1FF3B248B92A2159F9], host=[www.beta.ddcash.cn], origin=[http://www.beta.x.cn], referer=[http://www.beta.x.cn/], user-agent=[Mozilla/5.0 (Linux; Android 7.0; EVA-AL10 Build/HUAWEIEVA-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043124 Safari/537.36 MicroMessenger/6.5.8.1060 NetType/WIFI Language/zh_CN], x-forwarded-for=[10.254.30.59], x-real-ip=[10.254.30.59], x-requested-with=[com.tencent.mm] } Payload: {"name":"value"} 【响应信息】 ID: 1091 Response-Code: 200 Content-Type: application/json;charset=utf-8 Headers: {Content-Type=[application/json;charset=utf-8], Date=[Tue, 04 Jul 2017 17:14:55 GMT]} Payload: { "name":"value" } =================================================================
发表评论
-
基于阿里云服务器给部署的IIS应用服务器安装SSL证书
2020-04-15 11:05 276在IIS服务器上安装SSL证书 效果:将阿里云服务器上I ... -
HttpAsyncClient-异步开源框架
2018-06-27 13:09 951引用参考 --了解HttpAsyncClient https: ... -
Http请求与响应 contentType
2017-08-23 17:12 738Http请求 1、方法-URI-协议/版本; 2、请求头信息; ... -
HTTP、 SSL/TSL、 HTTPS、TCP/IP 协议
2017-06-12 18:33 661--引用参考 --SSL 安全套 ... -
https相关、http相关
2016-11-18 13:46 3891、Https相关 a、iOS安全系列之一:HTTPS ... -
Http Https 连接池
2013-04-28 09:43 6110引用参考: --Http请求连接池 - HttpClient ... -
Retrofit原理及使用
2013-02-22 13:06 1052引用参考 --Retrofit使用 https://blog. ... -
httpCore
2012-09-13 10:30 877引用参考 --HttpCore 教程(二) https://b ... -
了解HttpClient、httpclient获取指定的网页
2012-08-28 13:48 1368引用参考: --HttpClient超 ...
相关推荐
WebApi系列-通过HttpClient来调用WebApi接口.doc
本demo有两个例子test是作为服务端开启的,httpclient是客户端调用的,模拟服务端的test在启动后是没有界面的,要加上id才能看到json数据,httpclient的HttpClient33.java是测试类,最后的结果是接受到一个对象。...
包含了get和post各种参数形式及方法, public static U Post, T>(string url, T model, NameValueCollection headers = null) { return HttpClientHelper.Post, T>(url, model, headers); } public static U ...
包含翻译后的API文档:httpclient-4.5.6-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.httpcomponents:httpclient:4.5.6; 标签:apache、httpcomponents、httpclient、jar包、java、中文文档; 使用...
本教程是继使用HttpClient调用Web API只有的补充教程,主要讲解了如何在WPF中异步调用Web API且不阻塞主线程。
包含翻译后的API文档:httpclient-4.5.5-javadoc-API文档-中文(简体)版.zip 对应Maven信息:groupId:org.apache.httpcomponents,artifactId:httpclient,version:4.5.5 使用方法:解压翻译后的API文档,用...
包含翻译后的API文档:httpclient-4.5.3-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.apache.httpcomponents:httpclient:4.5.3; 标签:apache、httpcomponents、httpclient、jar包、java、中英...
包含翻译后的API文档:httpclient-4.5.2-javadoc-API文档-中文(简体)版.zip 对应Maven信息:groupId:org.apache.httpcomponents,artifactId:httpclient,version:4.5.2 使用方法:解压翻译后的API文档,用...
利用httpclient-4.3.1.jar、httpcore-4.3.jar包,很简单的用java实现httpget和httppost请求。
包含翻译后的API文档:httpclient-4.4-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.httpcomponents:httpclient:4.4; 标签:apache、httpcomponents、httpclient、jar包、java、API文档、中文版; ...
包含翻译后的API文档:httpclient-4.5.13-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.httpcomponents:httpclient:4.5.13; 标签:apache、httpcomponents、httpclient、jar包、java、中文文档; ...
java实现调用httpclient接口的类和方法,包括了get和post传参方式,简单易懂
HttpClient模拟http发送post和get请求
包含翻译后的API文档:httpclient-4.5.6-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.apache.httpcomponents:httpclient:4.5.6; 标签:apache、httpcomponents、httpclient、jar包、java、API...
包含翻译后的API文档:httpclient-4.5.12-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.httpcomponents:httpclient:4.5.12; 标签:apache、httpcomponents、httpclient、中文文档、jar包、java; ...
java调用.NET webAPI httpclient-4.2.5.jar httpclient-cache-4.2.5.jar httpcore-4.2.4.jar httpmime-4.2.5.jar fluent-hc-4.2.5.jar commons-codec-1.6.jar
httpClient httpPost httpGet 所需jar包 httpClient httpPost httpGet 所需jar包
http远程接口调用-httpClient+跳过SSL证书校验. 里面分别有3个httpClient的工具类代码。 还有一个专门为了跳过SSL证书校验的工具类。
包含翻译后的API文档:httpclient-4.5.3-javadoc-API文档-中文(简体)版.zip 对应Maven信息:groupId:org.apache.httpcomponents,artifactId:httpclient,version:4.5.3 使用方法:解压翻译后的API文档,用...
httpclient-4.5.3 api 中文版