blackberry - Encoding issue while writing data to OutputStream -


i working on balckberry mobile application. data , post server application on java.io.outputstream using javax.microedition.io.connection object. although setting "content-type" property connection still cannot correct encoded string on server side

please note that:

  • server works fine utf-8 encoded string have verified using poster
  • xml correctly encoded on client side before written outputstream can see in debug mode

anyone can find glitch below code.

            // client side code              // xml string xml , correctly encoded, can see arabic or chinese character in debug mode             byte[] requestbyte = xml.getbytes();              // compress request bytes array             // initialize connection              // set connection properties             con.setrequestmethod(httpconnection.post);             con.setrequestproperty("user-agent", "profile/midp-2.0 configuration/cldc-1.0");             con.setrequestproperty("content-type", "application/x-www-form-urlencoded");             con.setrequestproperty("content-encoding", "utf-8");              os = con.openoutputstream();             inputstream in = new bytearrayinputstream(requestbyte);             byte[] buffer = new byte[4096];             int bytesread = 0;             while ((bytesread = in.read(buffer)) > 0) {                 os.write(buffer, 0, bytesread);             } 

couple of things:

1) presume variable call xml, string. in case want is

byte[] requestbyte = xml.getbytes("utf-8");

2) there seems redundant code here:

        inputstream in = new bytearrayinputstream(requestbyte);         byte[] buffer = new byte[4096];         int bytesread = 0;         while ((bytesread = in.read(buffer)) > 0) {             os.write(buffer, 0, bytesread);         } 

why not replace with:

os.write(requestbyte, 0, requestbyte.length);


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -