Question

I am using WebRequest to POST to a signin page that redirects me to the page I really need to post to.

How can I post to this page that I have been redirected to? Here is the Code:

*****NEW STUFF*****

Here is what is happening after I post to the login page: GET /config/validate?.src=flickr&.pc=5134&.scrumb=6l14Ni2Pz3j&.pd=c%3DE0.GahOp2e4MjkX.5l2HgAoLkpmyPvccpVM-&.intl=us&.done=http%3A%2F%2Fwww.flickr.com%2Fsignin%2Fyahoo%2F%3Fredir%3D%252Fpeople%252Flindieb68%252Frelationship%252F

GET /signin/yahoo/?redir=%2Fpeople%2Flindieb68%2Frelationship%

GET /cookie_check.gne?pass=%2Fpeople%2Flindieb68%2Frelationship%2F&fail=register_cookies.gne

GET /people/lindieb68/relationship/

The last one is where I need to click a button. Should I just go through all these GETs and collect cookies? I will try it after dinner and let you know. I feel like this will work. I will update in a little bit.

        private CookieContainer LoginYahoo(CookieContainer cookies)
        {
            string appURL = "https://login.yahoo.com/config/login?.src=flickr&.pc=5134&.scrumb=0&.pd=c%3DE0.GahOp2e4MjkX.5l2HgAoLkpmyPvccpVM-&.intl=us&.done=https%3A%2F%2Flogin.yahoo.com%2Fconfig%2Fvalidate%3F.src%3Dflickr%26.pc%3D5134%26.scrumb%3D0%26.pd%3Dc%253DE0.GahOp2e4MjkX.5l2HgAoLkpmyPvccpVM-%26.intl%3Dus%26.done%3Dhttp%253A%252F%252Fwww.flickr.com%252Fsignin%252Fyahoo%252F%253Fredir%253D%25252Fpeople%25252Flindieb68%25252Frelationship%25252F&rl=1";
            string strPostData = ".tries=1&.src=flickr&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=0delt5h5l4df0&.v=0&.challenge=3DZF0DFFqdE0m.9MWnCq6LjUZ9gV&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.done=https%3A%2F%2Flogin.yahoo.com%2Fconfig%2Fvalidate%3F.src%3Dflickr%26.pc%3D5134%26.scrumb%3D0%26.pd%3Dc%253DE0.GahOp2e4MjkX.5l2HgAoLkpmyPvccpVM-%26.intl%3Dus%26.done%3Dhttp%253A%252F%252Fwww.flickr.com%252Fsignin%252Fyahoo%252F%253Fredir%253D%25252Fpeople%25252Flindieb68%25252Frelationship%25252F&.pd=flickr_ver%3D0%26c%3DE0.GahOp2e4MjkX.5l2HgAoLkpmyPvccpVM-%26ivt%3D%26sg%3D&login=loginName&passwd=Password&.persistent=y&.save=Sign+In";

            // Setup the http request.
            HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as
            HttpWebRequest;
            wrWebRequest.Method = "POST";
            wrWebRequest.ContentLength = strPostData.Length;
            wrWebRequest.ContentType = "application/x-www-form-urlencoded";
            CookieContainer cookieContainer = cookies;
            wrWebRequest.CookieContainer = cookieContainer; 

            // Post to the login form.
            StreamWriter swRequestWriter = new
            StreamWriter(wrWebRequest.GetRequestStream());
            swRequestWriter.Write(strPostData);
            swRequestWriter.Close();

            // Get the response.
            HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();

            // Read the response
            StreamReader srResponseReader = new
            StreamReader(hwrWebResponse.GetResponseStream());
            string strResponseData = srResponseReader.ReadToEnd();
            srResponseReader.Close();

            //YOU ARE NOW LOGGED IN TO YAHOO!
            //NEED TO POST AGAIN TO WHAT hwrWebResponse RETURNS
            ShowInBrowser(strResponseData);
            return cookieContainer;
        }
Was it helpful?

Solution

Collect all the cookies from the previous (login) responses as at least one of them will be the cookie that tells Yahoo that you have already logged in. Then include the cookies with your post requst to the destination page, or any other interaction with Yahoo.

Edit: See this article for a complete code example for collecting and re-using cookies.
http://blogs.msdn.com/dgorti/archive/2005/08/16/452347.aspx

OTHER TIPS

Set AllowAutoRedirect to true on your HttpWebREquest instance.

This is getting complicated.

The short answer seems to be Collect the Cookies. For some reason I fail at doing it though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top