dcsimg
How to properly reuse an <code>HttpConnection</code>?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tomek_Knyziak
Posted On:   Tuesday, October 29, 2002 03:11 AM

Hello, everyone. I wrote a midlet that contacts and internet server a few times, but I could only get it to work when I was opening a new HttpConnection every time. The trouble is I am getting billed for opening a new GPRS session each time so using my midlet becomes very expensive. I believe that reusing the same HttpConnection would solve the problem, but there goes another story: I'm opening the HttpConnection I'm opening an output stream and write some data (POST method) I'm closing the output stream I'm opening the input stream I'm dowloading data I'm closing the input stream    More>>

Hello, everyone.



I wrote a midlet that contacts and internet server a few times, but I could only get it to work when I was opening a new HttpConnection every time. The trouble is I am getting billed for opening a new GPRS session each time so using my midlet becomes very expensive. I believe that reusing the same HttpConnection would solve the problem, but there goes another story:




  1. I'm opening the HttpConnection
  2. I'm opening an output stream and write some data (POST method)
  3. I'm closing the output stream
  4. I'm opening the input stream
  5. I'm dowloading data
  6. I'm closing the input stream


So far it works fine, but when I try to go to step 2 again (without closing the HttpConnection ), nothing is posted to the server (as indicated by network monitor in Sun's WTK) and opening the input stream throws an IOException with a message that the stream is already open.


What do I do wrong?


The server is Tomcat 4.0 and surely supports HTTP/1.1


Thanks for any help


Tomek

   <<Less

Re: How to properly reuse an <code>HttpConnection</code>?

Posted By:   Jack_Lai  
Posted On:   Thursday, November 21, 2002 06:04 PM

I think you can set the head of HttpConnection,just like this

HttpConnection conn = (HttpConnection) Connector.open( url ) ;
conn.setRequestProperty("Connection","open");

After do that , you can make your HttpConnection "Keep Active" is a short time .And you should set the field "Content-Length" a correct value , else error will happen.

Maybe it can help you something . Good Luck!
About | Sitemap | Contact