| | |
| | | /** |
| | | * 执行有参GET请求,带请求头 |
| | | * |
| | | * @param url 请求url |
| | | * @param params 参数 |
| | | * @param key 请求头Key |
| | | * @param url 请求url |
| | | * @param params 参数 |
| | | * @param key 请求头Key |
| | | * @param secretKey 秘钥 |
| | | * @return |
| | | */ |
| | | public static String doGetHeader(String url, String key, String secretKey,Map<String, String> params) { |
| | | public static String doGetHeader(String url, String key, String secretKey, Map<String, String> params) { |
| | | |
| | | //获取httpclient客户端 |
| | | CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | |
| | | |
| | | if (null != params) { |
| | | for (String keys : params.keySet()) { |
| | | builder.addParameter(keys,params.get(keys)); |
| | | builder.addParameter(keys, params.get(keys)); |
| | | //builder.setParameter(keys, params.get(keys)); |
| | | } |
| | | } |
| | |
| | | HttpGet httpGet = new HttpGet(builder.build()); |
| | | |
| | | //设置请求头 |
| | | httpGet.addHeader(key,secretKey); |
| | | httpGet.addHeader(key, secretKey); |
| | | // 传输的类型 |
| | | httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded"); |
| | | //执行Http请求调用 |
| | |
| | | /** |
| | | * 执行有参GET请求,带请求头,接收图片流 |
| | | * |
| | | * @param url 请求url |
| | | * @param params 参数 |
| | | * @param key 请求头Key |
| | | * @param url 请求url |
| | | * @param params 参数 |
| | | * @param key 请求头Key |
| | | * @param secretKey 秘钥 |
| | | * @return |
| | | */ |
| | | public static String doGetHeaderPictureBase64(String url, String key, String secretKey,Map<String, String> params) { |
| | | public static String doGetHeaderPictureBase64(String url, String key, String secretKey, Map<String, String> params) { |
| | | |
| | | //获取httpclient客户端 |
| | | CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | |
| | | URIBuilder builder = new URIBuilder(url); |
| | | if (null != params) { |
| | | for (String keys : params.keySet()) { |
| | | builder.addParameter(keys,params.get(keys)); |
| | | builder.addParameter(keys, params.get(keys)); |
| | | } |
| | | } |
| | | HttpGet httpGet = new HttpGet(builder.build()); |
| | | //设置请求头 |
| | | httpGet.addHeader(key,secretKey); |
| | | httpGet.addHeader(key, secretKey); |
| | | // 传输的类型 |
| | | httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded"); |
| | | //执行Http请求调用 |
| | |
| | | |
| | | /** |
| | | * post 请求 header 带 秘钥 |
| | | * |
| | | * @param url |
| | | * @param appKey |
| | | * @param appKeyValue |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | |
| | | //适用于post请求并传送form-data数据(同样适用于post的Raw类型的application-json格式) |
| | |
| | | |
| | | /** |
| | | * json body |
| | | * |
| | | * @param url |
| | | * @param json |
| | | * @return |