1. 程式人生 > >Java HttpURLConnection 下載圖片 圖片全是“加密圖片”文字,怎麽解決?

Java HttpURLConnection 下載圖片 圖片全是“加密圖片”文字,怎麽解決?

int add tput read args ioe void zip lang

package com.qzf.util;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class ReadMdImg {
public static void main(String[] args) throws IOException {
HttpURLConnection con = (HttpURLConnection) new URL("http://www.madeinchina.cn/gongshang/CorpSel/InfoShowImg.aspx?StrCode=40E4972E6CF94E842C5574E9DCD4CEDB5B42D00BE36AB7E9886F8D2139C47C79").openConnection();
con.setRequestMethod("GET");
String cookie = "ASP.NET_SessionId=1p4pck552n2exv45acuonnm0; UserInfo=cardmunber=001000040762&logins=1&searchs=0&FIRST_DATE=2017/11/9&END_DATE=2018/11/9&IS_ZZ=0&CORP_NAME=%e5%bc%a0%e6%a0%8b%e6%a2%81&ADDS=1&LINKMAN=%e5%bc%a0%e6%a0%8b%e6%a2%81&TEL=15995885383; FengYe=RowCount=638577&PageCount=11611";
con.setRequestProperty("Cookie", cookie);
con.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)");
con.setRequestProperty("Host", "www.madeinchina.cn");
con.setRequestProperty("Accept", "text/html, application/xhtml+xml, */*");
con.setRequestProperty("Accept-Language", "zh-CN");
con.setRequestProperty("Accept-Encoding", "gzip, deflate");
con.setRequestProperty("Referer", "http://www.madeinchina.cn/gongshang/login.aspx");
InputStream in = con.getInputStream();
FileOutputStream out = new FileOutputStream("E:\\gongshang.jpg");
byte[] buf = new byte[1024];
int len = -1;
while((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
out.flush();
out.close();
in.close();
con.disconnect();
}
}

Java HttpURLConnection 下載圖片 圖片全是“加密圖片”文字,怎麽解決?