Uwe Seimet wrote:
Hello Oleg,
This is not what I am seeing in the wire log:
I am sorry, I pasted the wrong log. I see the same (empty charset
definition) in my log as you have observed.
The charset is wrong. So, HttpClient is correct in throwing an exception.
Yes, and I do not think that HttpClient does something wrong. What I
wonder is if there is a way to tell HttpClient to ignore this error.
Imagine someone would like to write a web browser based on HttpClient.
In contrast to other browsers like IE or Firefox the HttpClient-based
browser would be the only one not being able to display a web page with
missing charset information, because of this exception. This limits the
range of applications that can make use of HttpClient, which is a bit
sad.
Best regards, Uwe
Uwe,
The use of HttpMethod#getResponseBodyAsString() is *strongly* discouraged.
There are much better ways of consuming HTTP response body. This is what
I would recommend doing:
HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("http://www.whatever.com/");
try {
httpclient.executeMethod(httpget);
String charset = httpget.getResponseCharSet();
if (charset == null) {
charset = "UTF-8";
// or any other default charset
}
Reader reader = new InputStreamReader(
httpget.getResponseBodyAsStream(),
charset);
// do something useful
} finally {
httpget.releaseConnection();
}
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]