更新Https客户端

master
星期八 6 years ago
parent d1cac9240e
commit 732d469217
  1. 22
      panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java

@ -39,7 +39,7 @@ public class HttpsClient {
String resultStr = ""; String resultStr = "";
try{ try{
// 获得utf-8编码的mbuilder // 获得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? * 原生的微信使用的url是https://api.weixin.qq.com/cgi-bin/media/upload?
* access_token=##ACCESS_TOKEN##&type=##TYPE## * access_token=##ACCESS_TOKEN##&type=##TYPE##
@ -79,8 +79,6 @@ public class HttpsClient {
reponse = client.execute(post); reponse = client.execute(post);
// 获得返回的内容 // 获得返回的内容
HttpEntity entity = reponse.getEntity(); HttpEntity entity = reponse.getEntity();
// 输出
System.out.println(JSONObject.toJSONString(entity));
resultStr = JSONObject.toJSONString(entity); resultStr = JSONObject.toJSONString(entity);
@ -90,7 +88,6 @@ public class HttpsClient {
while (reader.ready()){ while (reader.ready()){
buffer.append((char)reader.read()); buffer.append((char)reader.read());
} }
System.out.println(buffer.toString());
} catch (ClientProtocolException e) { } catch (ClientProtocolException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } 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(); MultipartEntityBuilder result = MultipartEntityBuilder.create();
result.setBoundary(boundarStr) result.setBoundary(boundarStr)
.setCharset(Charset.forName(charSet)) .setCharset(Charset.forName(charSet))
@ -158,18 +155,5 @@ public class HttpsClient {
SSLContext context = SSLContext.getDefault(); SSLContext context = SSLContext.getDefault();
return context; 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<String, Object> params = new HashMap<String, Object>();
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);
}
} }

Loading…
Cancel
Save