我正在使用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并收集饼干吗?我会在晚餐后尝试一下让你知道。我觉得这样会有效。我会稍微更新一下。
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;
}
答案 0 :(得分:1)
收集上一个(登录)回复中的所有Cookie,因为其中至少有一个将是告知Yahoo您已经登录的Cookie。然后将包含您的帖子请求的Cookie包含到目标页面或任何其他与雅虎的互动。
编辑:有关收集和重复使用Cookie的完整代码示例,请参阅此文章 http://blogs.msdn.com/dgorti/archive/2005/08/16/452347.aspx
答案 1 :(得分:0)
在HttpWebREquest实例上将AllowAutoRedirect设置为true。
答案 2 :(得分:0)
这变得复杂了。
简短的回答似乎是收集Cookies。出于某种原因,我虽然做不到。