try{
System.out.println("get>>>"+httpUrl);
URL serverUrl = new URL(httpUrl);
java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(proxy);
conn.setRequestMethod("GET");//"POST" ,"GET"
// conn.setDoOutput(true);
/* if(refer != null){
conn.addRequestProperty("Referer", refer);
}*/
conn.addRequestProperty("Cookie", cookie);
conn.addRequestProperty("Accept-Charset", "utf-8");//GB2312,
conn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Firefox/3.6.8");
conn.connect();
if(conn.getHeaderFields().get("Set-Cookie") != null){
for(String s:conn.getHeaderFields().get("Set-Cookie")){
cookie += s;
}
}
InputStream ins = conn.getInputStream();
String charset = "utf-8";
InputStreamReader inr = new InputStreamReader(ins);
BufferedReader bfr = new BufferedReader(inr);
String line = "";
StringBuffer res = new StringBuffer();
do{
res.append(line);
line = bfr.readLine();
//System.out.println(line);
}while(line != null);
System.out.println(">>>==="+res);
return res.toString();
}catch(Exception e){
e.printStackTrace();
return null;
}
我开始以为获取所有的都乱码,后来才发现好像是utf8页面中,共手机专用的wml页面格式乱码,html正常
但是不管什么页面在sdk和平板电脑中一切正常
真的不知道为何会这样,请高手帮个忙.
部分乱码的网页源码
j��l�ZCache-Control��max-age=0���ZCache-Control��no-cache��{�F
System.out.println("get>>>"+httpUrl);
URL serverUrl = new URL(httpUrl);
java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(proxy);
conn.setRequestMethod("GET");//"POST" ,"GET"
// conn.setDoOutput(true);
/* if(refer != null){
conn.addRequestProperty("Referer", refer);
}*/
conn.addRequestProperty("Cookie", cookie);
conn.addRequestProperty("Accept-Charset", "utf-8");//GB2312,
conn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Firefox/3.6.8");
conn.connect();
if(conn.getHeaderFields().get("Set-Cookie") != null){
for(String s:conn.getHeaderFields().get("Set-Cookie")){
cookie += s;
}
}
InputStream ins = conn.getInputStream();
String charset = "utf-8";
InputStreamReader inr = new InputStreamReader(ins);
BufferedReader bfr = new BufferedReader(inr);
String line = "";
StringBuffer res = new StringBuffer();
do{
res.append(line);
line = bfr.readLine();
//System.out.println(line);
}while(line != null);
System.out.println(">>>==="+res);
return res.toString();
}catch(Exception e){
e.printStackTrace();
return null;
}
我开始以为获取所有的都乱码,后来才发现好像是utf8页面中,共手机专用的wml页面格式乱码,html正常
但是不管什么页面在sdk和平板电脑中一切正常
真的不知道为何会这样,请高手帮个忙.
部分乱码的网页源码
j��l�ZCache-Control��max-age=0���ZCache-Control��no-cache��{�F
return new String(strGBK.getBytes(),"UTF-8");
return new String(strGBK.getBytes(),"UTF-8");