# api **Repository Path**: yacongliu/api ## Basic Information - **Project Name**: api - **Description**: 基于Http协议的数据交互SDK - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-12-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # api 系统集成现阶段采用的较多的是基于Http+Json方式进行数据交互。本文将介绍的就是基于httpclient技术进行封装的SDK,方便日后其余项目的接口集成开发。 ## 技术选型 java httpclient ## 环境 jdk1.8 httpclient-4.5.4.jar httpcore-4.4.8.jar httpmime-4.5.4.jar log4j-1.2.17.jar self4j-api-1.7.25.jar slf4j-log4j12-1.7.25.jar commons-lang-2.6.jar commons-logging.jar ## 核心类 - GatewayAuth 基于HttpHelper类抽取出的常用方法 ![输入图片说明](https://app.yinxiang.com/shard/s2/res/db829fb9-ac36-405a-85f7-ccf3743b5553.png "在这里输入图片标题") ``` public class GatewayAuth { private static final String APPLICATION_JSON = "application/json"; private static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; private static final int timeoutMillis = 60000; public static String gatewayGet(String url) throws Exception { Map headers = new HashMap(1); return HttpHelper.get(url); } public static String gatewayPost(String url, Map param) throws Exception { Map headers = new HashMap(1); headers.put("Content-Type", "application/x-www-form-urlencoded"); return HttpHelper.post(headers, param, url, 60000); } public static String gatewayPostJson(String url, String param) throws Exception { Map headers = new HashMap(1); headers.put("Content-Type", "application/json"); return HttpHelper.post(headers, param, url, 60000); } } ``` - HttpHelper httpclient请求工具类 ![输入图片说明](https://app.yinxiang.com/shard/s2/res/81a616b8-7124-4aa5-b5af-f770817b4771.png "在这里输入图片标题")