commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Alexander" <dalexan...@ukgateway.net>
Subject HttpClient, reading response, problem
Date Mon, 21 Jul 2003 08:28:38 GMT
Hi,

I'm using Jakarta Commons HttpClient and am having trouble reading the
response to a GetMethod.


// execute method
byte[] bytes = method.getResponseBody();
String response = new String(bytes, "UTF-8");
// method.getResponseCharSet() returns "utf-8"
System.out.println(response);


Unfortunately this just displays garbage.

I added code to iterate through and print out the value of each byte. Some
come up negative which surprises me. If I put the first 50 or so values here
maybe someone can help identify what the problem is:



byte[] bytes = method.getResponseBody();
java.text.DecimalFormat df = new java.text.DecimalFormat("000");
for (int i=0; i<bytes.length; i++)
{
	System.out.print(df.format(bytes[i])+" ");
      if ((i+1)%20 == 0)
         System.out.print('\n');
}


031 -117 008 000 000 000 000 000 000 011 -115 086 075 111 -029 054
016 -066 -025 087
008 -070 056 001 -078 090 -110 018 -011 -088 031 064 -110 -090 -040 093
036 -023 -042 -021
108 015 069 015 -076 -060 -040 066 -012 048 036 058 -117 -004 -005 114 -122
018 035 -045

...

It should read

<html><head><meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<script language="Javascript">

...


If I make the request using IE6, it can read the response and says it is
UTF-8 encoding.
Snooping on the request and response headers they look the same whether I
use IE6 or HttpClient.


Thanks


Mime
View raw message