-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Paritosh,
On 7/15/2011 11:23 AM, Paritosh Patel wrote: > The client specified content-type to be > "application/x-www-form-urlencoded" right now, but I have tried > several others. Note that application/x-www-form-urlencoded requires that you properly set the "Content-Type" header with an appropriate "charset" parameter. Are you doing that? If not, your stuff will break. > Then, for encoding, I have tried encoding the bytes using URLEncoder > > ByteArrayOutputStream osBytes = new ByteArrayOutputStream(); byte[] > val = "..." // My binary data String valStr = new String((byte[]) > val); osBytes.write(URLEncoder.encode(valStr, "UTF-8").getBytes()); So, a few problems, here. First, new String(byte[]) will destroy your data because you are not specifying a charset to use. Second, never put binary data into a String because it's going to end up destroyed. Second, URLEncoding the string will just make things worse. You don't need ? changed to %whatever, etc. > DataOutputStream os = new > DataOutputStream(urlConn.getOutputStream()); > os.write(osBytes.toByteArray()); > > Now, on the servlet side, I do a request.getParameter() to get the > field. It is already decoded (I assume URL decoding) by the servlet > container. Do I have control over the decoding? Okay, you're in a giant mess at this point. Instead of continuing to read what it certainly to be a great tale of tilting at windmills, let me make two suggestions (pick one): 1. Use base64-encoded values and treat them as strings. The only changes would be to base64-encode the value before you stick it into the form (where it becomes an ASCII-compatible string) and then de-code it in your servlet. 2. Use multipart/form-data and have a separate MIME part that has MIME type of application/octet-stream where you dump your raw bytes to the binary stream. Note that you can't use a "writer" to write this data: you must use an OutputStream. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk4gnTIACgkQ9CaO5/Lv0PApogCgkSezcapQx+D2i5qW7SI79lAy aXIAoIZoFUVsI47hU/pSRoZjDGmIxqsM =3War -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org