From 732d4692179dc1065ba2f124cbd03d85bca6a932 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Mon, 20 May 2019 15:07:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0Https=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/panda/code/uitl/http/HttpsClient.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java b/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java index 6280d50..30f6813 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java +++ b/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java @@ -39,7 +39,7 @@ public class HttpsClient { String resultStr = ""; try{ // 获得utf-8编码的mbuilder - MultipartEntityBuilder mBuilder = get_COMPATIBLE_Builder(DETAFILE_CHARSET,boundary); + MultipartEntityBuilder mBuilder = getCompatibleBuilder(DETAFILE_CHARSET,boundary); /** * 原生的微信使用的url是https://api.weixin.qq.com/cgi-bin/media/upload? * access_token=##ACCESS_TOKEN##&type=##TYPE## @@ -79,8 +79,6 @@ public class HttpsClient { reponse = client.execute(post); // 获得返回的内容 HttpEntity entity = reponse.getEntity(); - // 输出 - System.out.println(JSONObject.toJSONString(entity)); resultStr = JSONObject.toJSONString(entity); @@ -90,7 +88,6 @@ public class HttpsClient { while (reader.ready()){ buffer.append((char)reader.read()); } - System.out.println(buffer.toString()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { @@ -118,7 +115,7 @@ public class HttpsClient { } - private static MultipartEntityBuilder get_COMPATIBLE_Builder(String charSet,String boundarStr) { + private static MultipartEntityBuilder getCompatibleBuilder(String charSet,String boundarStr) { MultipartEntityBuilder result = MultipartEntityBuilder.create(); result.setBoundary(boundarStr) .setCharset(Charset.forName(charSet)) @@ -158,18 +155,5 @@ public class HttpsClient { SSLContext context = SSLContext.getDefault(); return context; } - - public static void main(String[] args) throws IOException { - File file =new File("/Users/qi_liang/Downloads/timg.jpeg"); - String url = "https://api.weixin.qq.com/cgi-bin/media/upload"; - Map params = new HashMap(); - params.put("access_token", "10_0oKKCsF9JL30JeGZDyfNWDhiaRvivAL9vs9ihvaledzBuPVM6IMvwcFUc58AFwlETRdvEBAFXOYbF2GoKmbtMmopCs78m9UE8whgrYU4kJww4mSooMcq8el-qnU4JdjPGKruZLjdNS246hXyWOHbAAAHZS"); - params.put("type", "image"); - if(file.exists()){ - params.put("media", file); - } - String resultStr = post(url,params); - System.out.println(resultStr); - } - + }