I apologize in advance if this is not the correct mail list for such a
question, but this is the closest one I could find.
(I am using Tomcat 6.0.26 but my question is generic in nature)
I have a Java client that talks to a servlet using several text fields. I now
wanted to add a field that includes binary data (in this case a protocol buffer
byte array). The data gets to the servlet, but the bytes are changed.
Specifically, it appears that the encoding/decoding of bytes > 127 are not the
same as the original bytes.
The client specified content-type to be "application/x-www-form-urlencoded"
right now, but I have tried several others. 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());
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?
A portion of the byte array at the client is as follows...
31 12 e 8 ac e2 cb 8c 90 26 10 90
There are several variables, that I need to get right at the same time.
1) content-type... what is the correct content type
2) encoder... is URLEncoder the correct encoder?
3) encode string... UTF-8 and US-ASCII do not work.
4) do I have control over the decoding on the servlet side?
5) anything else I need to worry about?
Any help would be greatly appreciated.
- Tosh