请求获取图片接口返回数据 类型确实是图片 但是一堆乱码 请教大神 如何处理 Java啊代码实现
下面的发送GET请求的方法
public static String sendGet(String url) {
String result = "";
BufferedReader in = null;
try {
URL realUrl = new URL(url);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
Map map = connection.getHeaderFields();
Iterator line = map.keySet().iterator();
while(line.hasNext()) {
String key = (String)line.next();
System.out.println(key + "--->" + map.get(key));
}
String line1;
for(in = new BufferedReader(new InputStreamReader(connection.getInputStream())); (line1 = in.readLine()) != null; result = result + line1) {
;
}
} catch (Exception var17) {
System.out.println("发送GET请求出现异常!" + var17);
var17.printStackTrace();
} finally {
try {
if(in != null) {
in.close();
}
} catch (Exception var16) {
var16.printStackTrace();
}
}
return result;
}
/**
* 获取微信的服务器上传的媒体文件
* @param acctoken
* @param serviceId
* @return
*/
public static String getWechatMedia(String acctoken,String serviceId){
String requestUrl = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+acctoken+"&media_id="+serviceId;
String sendGet = HttpRequestUtil.sendGet(requestUrl);
return sendGet;
}
最后打印sendGet 就是一堆乱码数据
新手请教大神 帮忙看看,着急