• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

HttpsURLConnection

 
Greenhorn
Posts: 22
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 222
Google Web Toolkit Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tell me, is there is any class which send/receive multiple request/response using single connection?
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Google Web Toolkit Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Now I able to send multiple request without exception.
I used MultithrededHttpConnectionHandler class to accomplish this.
Thanks.
 
I love a good mentalist. And so does this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic