×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

为什么用java读,网页的charset=iso-8859_1, 网页上的汉字为乱码,直接用浏览器下载,网页的charset=utf8? 有经验的帮我分析一下。URL: http://babelfish.yahoo.com/translate_txt

本文发表在 rolia.net 枫下论坛Java code:

..........................................
..........................................

URL url;
URLConnection urlConn;
DataOutputStream printout;

BufferedReader input;

url = new URL("http://babelfish.yahoo.com/translate_txt");

urlConn = url.openConnection();
urlConn.setConnectTimeout(0);

urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestProperty("content-type", "text/html;charset=utf-8");

// Send POST output.
printout = new DataOutputStream(urlConn.getOutputStream());
String content =
"trtext=" + URLEncoder.encode(msg, "UTF8") +
"&lp=" + URLEncoder.encode(lang, "UTF8");

System.out.println("trtext=" + msg);
System.out.println("&lp=" + lang);

printout.write(content.getBytes(), 0, content.getBytes().length);
printout.flush();
printout.close();

input = new BufferedReader ( new InputStreamReader( urlConn.getInputStream (), "UTF8" ) );

String str, str_1;
int i = 0;
str = "not available";

while (null != (str_1 = input.readLine())) {

str = str_1;
System.out.println(str);
}

........................
........................更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report