Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
mika singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic