Hi, I have some serious problems with the HTTPConnection interface for J2ME. I'm trying to get a persistent connection with a HTTP 1.1 server but I can't achieve it! What I really want is to send some "chunked data" to the sever and then the server processes them separately! I don't know how to get it and I need your help!
I've read in the HTTP 1.1 RFC and in a lot of websites that the server and the client can close the HTTP connection if they include the "Connection" Header with the value "close". I'm extremely amazed that it doesn't exist a token like "open" to signal that the connection is persistent when the client does the POST request to the server! I don't want to send that "chunked data" in different HTTP connections, so I need a persistent connection!
Some questions for you:
1) If I write in an outputStream associated to the HTTP connection more than once, Will an Exception take place? Will the server receive the data?
2) How can the server receive those "chunked data" and decode them in a good way?
3) Why the HTTP architecture works so well in J2ME when the server sends data (chunked data or normal data) to the client but not when the roles change?
4) Do you have some problems with HTTP POST in J2ME?
I must tell you tha I'm using "Ethereal" tool, and I've advised that by default, an HTTP connection in J2ME has the "Connection" Header with the value "close" and if I explicitly write the value "open" in that Header, in the packet received by the server appears the token "close" again!
Please, help me with your ideas!
Here is a piece of my code:
//Set the request method and headers
httpConnection.setRequestProperty("If-Modified-Since","29 March 2006 20:00 GMT");
httpConnection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC 1.1");
//Open the OutputStream
OutputStream os = httpConnection.openOutputStream();
//Send the request body
byte buffer=new byte;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
baos.write("idPaciente=Emilio&idSensor=sensorE&tramaF1=".getBytes() baos.write(buffer); httpConnection.setRequestProperty("Content-Length",Integer.toString(baos.size())); os.write(baos.toByteArray());
//Get the response code and displays it in the Form