By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

HttpWebRequest with java session id cookie; HELP PLEASE

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Amil wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #2

P: n/a
Been there...tried that.

Amil

"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn***************@msnews.microsoft.com...
Amil wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 19 '05 #3

P: n/a
Amil wrote:
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,

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.