This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes HttpsURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HttpsURLConnection" Watch "HttpsURLConnection" New topic
Author

HttpsURLConnection

Ashish Kirpan
Greenhorn

Joined: Jan 24, 2011
Posts: 22

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

Joined: Mar 08, 2010
Posts: 222

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.


Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ashish Kirpan
Greenhorn

Joined: Jan 24, 2011
Posts: 22

tell me, is there is any class which send/receive multiple request/response using single connection?
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Since JDK supports Http Connection reuse transparently, why do you want to do it yourself?


Thanks and Regards
Elchin Asgarli
Ranch Hand

Joined: Mar 08, 2010
Posts: 222

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

Joined: Jan 24, 2011
Posts: 22

is there is any substitute class for sending/receiving multiple request/response ???
Ashish Kirpan
Greenhorn

Joined: Jan 24, 2011
Posts: 22

Hi All,
Now I able to send multiple request without exception.
I used MultithrededHttpConnectionHandler class to accomplish this.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpsURLConnection
 
Similar Threads
LDAP over HttpURLConnection?
HttpURLConnection
how to use make HTTP request behind a proxy server
Https url connection ArrayIndeoutofBounds Exception java
Email expiry setup in exchange web service