Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

writing output after input in data streams  RSS feed

 
Siddesh Kamat
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I am writing a console application to send multiple requests to the Northwest Airlines web server. As soon as I send a query string, I receive a page having a meta tag giving the url of the page where the request could be redirected. I am using the same urlConnection to first send my request, get the output from the server, then send back the query to the new url and get the page having the final result.
However, I am getting the following exception:
Exception in thread "main" java.net.ProtocolException: Cannot write output after reading input.
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
Can anybody help me out with how to take care of this,
Thanks,
Sid
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Exception in thread "main" java.net.ProtocolException: Cannot write output after reading input.
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)

Your connection object should be new for every request.
Eugene.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, you need a new connection. Rest assured, though, that behind the scenes Java will use HTTP keepalive if possible.
- Peter
 
Siddesh Kamat
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter and Eugene,
Thanks a lot...
Sid
 
Slamer Slamer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm already using an Http Tunneling between an applet and a servlet... All work fine without session tracking. Actually, I want to keep the session tracking between the both side. Unfortunately if I reset the connection for every request all the session information will be loosed!
Have you an idea to resolve that?
Thanks a lot,
Slamer
 
yuanfu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Slamer Slamer:
Hi,

I'm already using an Http Tunneling between an applet and a servlet... All work fine without session tracking. Actually, I want to keep the session tracking between the both side. Unfortunately if I reset the connection for every request all the session information will be loosed!
Have you an idea to resolve that?
Thanks a lot,
Slamer


i have the same problem.

frequent openConnection will affect performance?

anybody can tell me how to do the above question.

i need your help.
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session id is stored in the cookie. after reset connection, you must send that cookie to the server
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!