K
Kevin
Hi, All! I am spending days now trying to get a simple program to
work.
I want to query Google with Unicode-included (Chinese,Japanese) queries
with URLConnection.
Try this on your favorite Browser:
http://www.google.com/search?hl=en&lr=&q=新宿+&start=0&sa=N
If you go to your browser (choose View->Encoding) , you will see that
the the browser automatically set it to (UTF-8). If you manually
change it to ISO, and, type in the URL again, then the search returns
wrong results.
It seems that I need to set the HTTP request correctly to UTF-8. How
do I do that?
I am using the following code, and it is NOT working.
**************************************************************
URL urlObject = new URL(url);
HttpURLConnection con = (HttpURLConnection)urlObject.openConnection();
con.setRequestProperty ( "User-Agent","Mozilla/4.71 [en] (WinNT; I)");
con.setRequestProperty("Content-Type", "x-www-form-urlencoding;
charset=UTF8");
con.setRequestProperty("Content-Encoding", "UTF8");
System.out.println(con.getRequestProperty("Content-Type")) ;
BufferedReader webData = new BufferedReader(new
InputStreamReader(con.getInputStream(), "UTF8"));
**************************************************************
Thanks!
Kevin
work.
I want to query Google with Unicode-included (Chinese,Japanese) queries
with URLConnection.
Try this on your favorite Browser:
http://www.google.com/search?hl=en&lr=&q=新宿+&start=0&sa=N
If you go to your browser (choose View->Encoding) , you will see that
the the browser automatically set it to (UTF-8). If you manually
change it to ISO, and, type in the URL again, then the search returns
wrong results.
It seems that I need to set the HTTP request correctly to UTF-8. How
do I do that?
I am using the following code, and it is NOT working.
**************************************************************
URL urlObject = new URL(url);
HttpURLConnection con = (HttpURLConnection)urlObject.openConnection();
con.setRequestProperty ( "User-Agent","Mozilla/4.71 [en] (WinNT; I)");
con.setRequestProperty("Content-Type", "x-www-form-urlencoding;
charset=UTF8");
con.setRequestProperty("Content-Encoding", "UTF8");
System.out.println(con.getRequestProperty("Content-Type")) ;
BufferedReader webData = new BufferedReader(new
InputStreamReader(con.getInputStream(), "UTF8"));
**************************************************************
Thanks!
Kevin