本文发表在 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
..........................................
..........................................
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