HttpWebRequest with java session id cookie; HELP PLEASE

A

Amil

Please don't repond to this if you are guessing or just don't know the
answer.

I'm trying to login to a backend system running Java/Tomcat. I create a
HttpWebRequest with the login data and do a POST. This works fine. The
HttpWebResponse content I get back is just javascript "window.location=xxx"
(with normal html around it). The HttpWebResponse also contains a java
session id cookie. Fine so far.

I want to go to the new location (assume I parse it out); I create a second
HttpWebRequest with a new cookie container and add the java session id
cookie to the request:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(xxx);
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response.Cookies); // add in java session id
cookie

When I submit this request, I end up back at the login page...sort of like
it doesn't think I've logged in. I've verified that the outgoing request
contains the java session id cookie. I've also played around with setting
some of the request properties (e.g. timeout, content-type, user-agent,
request.accept, etc), but no luck.

It accepts my login; any idea on why when I create a second request, the
request is not valid? Anything I'm missing here? Thanks.

Amil
 
J

Joerg Jooss

Amil said:
Please don't repond to this if you are guessing or just don't know the
answer.

I'm trying to login to a backend system running Java/Tomcat. I
create a HttpWebRequest with the login data and do a POST. This
works fine. The HttpWebResponse content I get back is just
javascript "window.location=xxx" (with normal html around it). The
HttpWebResponse also contains a java session id cookie. Fine so far.

I want to go to the new location (assume I parse it out); I create a
second HttpWebRequest with a new cookie container and add the java
session id cookie to the request:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(xxx);
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response.Cookies); // add in java
session id cookie

When I submit this request, I end up back at the login page...sort of
like it doesn't think I've logged in. I've verified that the
outgoing request contains the java session id cookie. I've also
played around with setting some of the request properties (e.g.
timeout, content-type, user-agent, request.accept, etc), but no luck.

It accepts my login; any idea on why when I create a second request,
the request is not valid? Anything I'm missing here? Thanks.

You have to create a CookieContainer before the *first* request and use
that with all of your requests. It will keep track of incoming cookies
automatically.

Cheers,
 
A

Amil

Been there...tried that.

Amil

Joerg Jooss said:
You have to create a CookieContainer before the *first* request and use
that with all of your requests. It will keep track of incoming cookies
automatically.

Cheers,
 
J

Joerg Jooss

Amil said:
Been there...tried that.

That's a pretty useless statement in order to solve the problem. How
about posting your code? Are you sure you're really posting everything
that the web application expects?

Cheers,
 
Joined
May 5, 2011
Messages
1
Reaction score
0
BBOYSE

I maded. Quiet simple,

Look at this code, works perfect . Just an Example




Public Sub checkstatus() Handles ButtonLookUp.Click
Dim request, request1 As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim response1 As HttpWebResponse = Nothing
Dim reader As StreamReader

Dim urlMainLocation, urlTargetLocation As String
urlMainLocation = "http://www.ymland.com/invisible-scanner/"
urlTargetLocation = urlMainLocation + "checkid.php?nick=" & Me.yahooNickname.Text

Try
' Create the web request
request = DirectCast(WebRequest.Create(urlMainLocation), _
HttpWebRequest)
request.CookieContainer = New CookieContainer
request.CookieContainer.Add(request.CookieContainer.GetCookies(New Uri(urlMainLocation)))

' Add authentication to request
'request.Credentials = New NetworkCredential("username", "password")

' Get response
response = DirectCast(request.GetResponse(), HttpWebResponse)


request1 = DirectCast(WebRequest.Create(urlTargetLocation), _
HttpWebRequest)
request1.CookieContainer = New CookieContainer
request1.CookieContainer.Add(response.Cookies)

response1 = DirectCast(request1.GetResponse(), HttpWebResponse)

' Get the response stream into a reader
reader = New StreamReader(response1.GetResponseStream())

' Console application output
'Console.WriteLine(reader.ReadToEnd())
MsgBox(reader.ReadToEnd.ToString)
Finally
If Not response Is Nothing Then response.Close()
End Try

End Sub


------------
As you see, every time the webrequest.create(..) its made , it itself make a new instance.
I used the first "target" to get what i need (the cookies ,sess,etc)
and the secound , i just put in it.
Without cookies on the secound target , you'wll receive the Document source: "Banned" .
(because its missing the PHPSESSID cookie session.

;)
If you have more question write me on Yahoo Messenger: break_boty

PS: (its in WPF)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top