Java HttpURLConnection 下载图片 图片全是“加密图片”文字,怎么解决?
Posted 锋齐叶落
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java HttpURLConnection 下载图片 图片全是“加密图片”文字,怎么解决?相关的知识,希望对你有一定的参考价值。
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 下载图片 图片全是“加密图片”文字,怎么解决?的主要内容,如果未能解决你的问题,请参考以下文章
HttpURLConnection从链接下载数据存放本地临时文件,Java
java中HttpURLConnection利用url获取文件流下载,while循环提前结束?
Java HttpURLConnection 下载图片 图片全是“加密图片”文字,怎么解决?
Android开发之下载服务器上的一张图片到本地java代码实现HttpURLConnection