Reputation: 60
If I copy and past the following URL in the browser, I get a response URL with a query string sessionid in it:
https://abc.abcdefg.com/abcd/sessionServlet
I am trying to capture that response URL and session id in my code behind in .net:
string url = "https://abc.abcdefg.com/abcd/sessionServlet";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Label1.Text = response.ResponseUri.ToString();
the response.ResponseUri contains my original URL, but not the response URL I get back from the sessionServlet.
Could anyone help me? Thank you in advance.
Upvotes: 0
Views: 5152
Reputation: 16595
Looking at your comment about the http://devserver/myproject/login.aspx?sessionid=1341351j1oij4o1i3o13i5ho1i3j4134o
URL appearing the browser from vising the URL https://abc.abcdefg.com/abcd/sessionServlet
, you're probably being redirected using HTTP 301 or 302.
If so, I'd add request.AllowAutoRedirect = true
MSDN which will allow your web request to follow that redirect. Then response.ResponseUri.Query
should have the querystring that you're looking for.
Upvotes: 1