日期:2014-05-17  浏览次数:20644 次

返回乱码怎么处理?
这是我的java代码
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer("http://www.ip168.com/mobile/?mobile=1391632");
URL url = new URL(sb.toString());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// connection.setRequestProperty(arg0, arg1);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputline = in.readLine();
inputline=URLDecoder.decode(inputline, "utf-8");

System.out.println(inputline);
}
就这一个方法,是查询手机归属地,但是返回的结果汉字都是乱码,在别人机器上都没乱码,但是我的eclipse编码格式已经给设成utf-8了啊,怎么回事???

------解决方案--------------------
把编码换成gbk和gb2312 试试
------解决方案--------------------
可能是eclipse控制台 你看看window--preferences--editors--text editors--spelling
里的encoding 是utf-8不
------解决方案--------------------
connection.setRequestMethod("GET"); get改成post试试 还有页面上的form也要改成post提交
------解决方案--------------------
是滴,写一个监听器就可以了。