This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Sockets and Internet Protocols and the fly likes how to set JSESSIONID to second request,which is getting from first respone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how to set JSESSIONID to second request,which is getting from first respone" Watch "how to set JSESSIONID to second request,which is getting from first respone" New topic
Author

how to set JSESSIONID to second request,which is getting from first respone

mika singh
Greenhorn

Joined: Aug 22, 2011
Posts: 9
Hi,

I am able to create a connection using HttpUrlConnection and getting JSessionID. After that I set that value in request header like
connection.addRequestProperty("Cookie", session); here session is JSESSIONID=D1EA46859B6BC9C488A7A29F5AEE2521;
But it is throwing
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
Exception. Please let me know, how to set JSESSIONID to sencond request.
Thanks in Advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19677
    
  18

You don't need to do anything yourself, except start using a CookieHandler. Even that is really easy:
That's enough for simple solutions. It will use an in-memory CookieStore, and a CookiePolicy.ACCEPT_ORIGINAL_SERVER as the CookiePolicy. You can change both if you want or need to; for instance, a custom CookieStore implementation that uses the file system or a database to store the cookies, and CookiePolicy.ACCEPT_ALL to accept all cookies.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: how to set JSESSIONID to second request,which is getting from first respone