POST 到 WebResponse 返回的页面

发布于 2024-08-18 06:50:30 字数 3302 浏览 4 评论 0原文

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

我如何才能发布到我已重定向到的此页面?这是代码:

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

以下是我发布到登录页面后发生的情况: 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/

最后一个是我需要单击按钮的位置。我应该浏览所有这些 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;
        }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

红玫瑰 2024-08-25 06:50:30

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

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

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

情丝乱 2024-08-25 06:50:30

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

Set AllowAutoRedirect to true on your HttpWebREquest instance.

亚希 2024-08-25 06:50:30

这变得越来越复杂。

简短的答案似乎是收集饼干。但出于某种原因,我未能做到这一点。

This is getting complicated.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文