0

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.

2
  • Response URL? Is the content you are trying to obtain apart of the response body, or is it in the headers? Commented Nov 26, 2013 at 16:41
  • So i paste that URL in the browser, and i get this url back in the browser: devserver/myproject/…. I would like to retrieve this url so i could continue with the session id. Commented Nov 26, 2013 at 16:47

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I thought the AllowAutoRedirect is set to true by default? I added it in my code but still am not getting the URL with the session id.
@Hello_Everyone You're correct, the default is true, but wanted to ensure it was following it. If it isn't following it, then it's probably redirecting you using some other method like Javascript or a <meta> tag. May want to use something like Fidder or Wireshark to see what exactly is going on to get you to that page with the session ID.
Used fiddler, found out that it's redirecting me to the dev server, so it's not picking up the query string in my local. Problem solved. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.