|
|
|
@ -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)) |
|
|
|
@ -159,17 +156,4 @@ public class HttpsClient { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|