How can I read HTTP stream with HTML page in page's encoding?
Here is a code fragment I use to get the HTTP stream. InputStreamReader has the encoding optional argument, but I have no ideas about the way to obtain it.
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
BufferedReader d = new BufferedReader(new InputStreamReader(is));
Retrieving a Webpage is a reasonably complicated process. That's why libraries such as HttpClient exist. My advice is that unless you have a really compelling reason otherwise, use HttpClient.
When the connection is establised thru
URLConnection conn = url.openConnection();
you can get the encoding method name thru url.getContentEncoding() so pass this String to InputStreamReader() so the code looks like
BufferedReader d = new BufferedReader(new InputStreamReader(is,url.getContentEncoding()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With