Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpsURLConnection

 
Ashish Kirpan
Greenhorn
Posts: 22
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to send and receive multiple request/response using Single conection of HttpsURLConnection.
but when i try using single connection for second request it gives me exception java.net.ProtocolException: Cannot write output after reading input
please help me....
 
Elchin Asgarli
Ranch Hand
Posts: 222
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember having similar problems with HttpsURLConnection once, the thing is to get output from HttpsURLConnection, you have to first write things that you need to output stream, close it(!), and then start reading input stream. I don't know how to make multiple requests and responses though, my wild guess is that you could play with keepAlive parameter, or just use some kind of connection caching framework.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know very little about this subject so feel free to correct me. One of the first lines of the javadoc of HttpURLConnection is:

Each HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances.

So it's not intended to be used that way.
 
Ashish Kirpan
Greenhorn
Posts: 22
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tell me, is there is any class which send/receive multiple request/response using single connection?
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since JDK supports Http Connection reuse transparently, why do you want to do it yourself?
 
Elchin Asgarli
Ranch Hand
Posts: 222
Chrome Eclipse IDE Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satya Maheshwari wrote:Since JDK supports Http Connection reuse transparently, why do you want to do it yourself?


Cause he needs https connection, not http.
 
Ashish Kirpan
Greenhorn
Posts: 22
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there is any substitute class for sending/receiving multiple request/response ???
 
Ashish Kirpan
Greenhorn
Posts: 22
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Now I able to send multiple request without exception.
I used MultithrededHttpConnectionHandler class to accomplish this.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic