0

我正在使用 WebRequest 发布到登录页面,该页面将我重定向到我真正需要发布的页面。

我如何发布到我被重定向到的这个页面?这是代码:

*****新的东西*****

这是我发布到登录页面后发生的事情: 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

获取 /signin/yahoo/?redir=%2Fpeople%2Flindieb68%2Frelationship%

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

获取 /people/lindieb68/relationship/

最后一个是我需要单击按钮的地方。我应该通过所有这些 GET 并收集 cookie 吗?我会在晚饭后试一试,然后告诉你。我觉得这会奏效。我会在一点点更新。

        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;
        }
4

3 回答 3

1

从之前的(登录)响应中收集所有 cookie,因为其中至少有一个是告诉雅虎您已经登录的 cookie。然后将 cookie 包含在您对目标页面的发布请求中,或与雅虎的任何其他交互中.

编辑:有关收集和重用 cookie 的完整代码示例,请参阅本文。
http://blogs.msdn.com/dgorti/archive/2005/08/16/452347.aspx

于 2010-01-16T23:11:26.230 回答
0

这变得越来越复杂。

简短的回答似乎是收集 Cookie。出于某种原因,我没有做到这一点。

于 2010-01-17T03:16:16.557 回答
0

在 HttpWebREquest 实例上将 AllowAutoRedirect 设置为 true。

于 2010-01-16T22:16:33.370 回答