Hi again. > > > > I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]" > I think, just using the default platform encoding is as bad as using > US-ASCII because it does not reflect was is *really* sent over the wire.
If you look closely, you will see that this is _not:_ the default character encoding. This actually what *really* is sent over the wire. Of course I can see the advantage of a full hex dump, but this would more be an addition to the functionality, but my fix would be more like a bug-fix. To demonstrate I have made a small code snipplet derived from the Wire.java. This code should be runnable and print out the log: : -------------- public class EncodingTest { public static void main(String[] args) throws IOException { // Setup: byte[] b = new byte[]{(byte) 0xc3, (byte) 0xa6, (byte) 0xc3, (byte) 0xb8, (byte) 0xc3, (byte) 0xa5}; ByteArrayInputStream instream = new ByteArrayInputStream(b); //------ // ------ Old code: ------- // Reader reader = null; // try { // reader = new InputStreamReader(instream, "US-ASCII"); // } catch (UnsupportedEncodingException e) { // reader = new InputStreamReader(instream); // } // ------------------------ StringBuffer buffer = new StringBuffer(); int ch; // ------ Old code: ------- // while ((ch = reader.read()) != -1) { // ------ Old code: ------- // ------ New code: ------- while ((ch = instream.read()) != -1) { // ------------------------ if (ch == 13) { buffer.append("[\\r]"); } else if (ch == 10) { buffer.append("[\\n]\""); buffer.insert(0, "\""); System.out.println(buffer.toString()); buffer.setLength(0); } else if ((ch < 32) || (ch > 127)) { buffer.append("[0x"); buffer.append(Integer.toHexString(ch)); buffer.append("]"); } else { buffer.append((char) ch); } } if (buffer.length() > 0) { buffer.append("\""); buffer.insert(0, "\""); System.out.println(buffer.toString()); } } } -----Original Message----- From: Ortwin Glück [mailto:[EMAIL PROTECTED] Sent: 31. mars 2004 11:14 To: Commons HttpClient Project Subject: Re: The httpclient.wire log. Geir H. Pettersen wrote: > Hi, > > I have been using the commons httpclient successfully since rc1. Great work > guys! This is the best client that I ever have used in java. Thanks for the flowers, Geir! > The httpclient.wire log is fantastic, but there is something there that > bothers me a bit. Before the characters are written to log, they are decoded > with "US-ASCII" (or the default character set if that fails). > > The problem with this is if you try to debug http traces with special > character you will actually lose information on what is actually sent. > > My example is: I am having some encoding problems with my client, and I want > to check exactly what bytes I am sending. I am sending the three Norwegian > characters (1)ĉ (2)ĝ and (3)ċ. (ae together, o with a slash and a with a > ring over). > > (1) is encoded in UTF-8 as 0xc3 0xa6 > (2) is encoded in UTF-8 as 0xc3 0xb8 > (3) is encodes in UTF-8 as 0xc3 0xa5 > > The problem is when I try to POST these three characters. It is logged as: > "[0xfffd][0xfffd][0xfffd][0xfffd][0xfffd][0xfffd]" (but actually that is not > what is sent) > > I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]" I think, just using the default platform encoding is as bad as using US-ASCII because it does not reflect was is *really* sent over the wire. Actually the wirelog should ideally provide all bytes in hexadecimal representation along with their supposed interpretation as characters in some encoding (such as default platform encoding). A presentation similar to hexdumps would me nice IMHO. However this might imply a small buffering (16 bytes per line) to make a nice layout. Sample output (hex values do not match text): DE AD BE EF DE AD BE EF DE AD BE EF DE AD BE EF GET /index.htm H DE AD BE EF DE AD BE EF DE AD BE EF DE AD BE EF TTP/1.1..Host:ww --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]