【发布时间】:2014-10-16 12:38:04
【问题描述】:
最近几天我一直在解决这个问题,终于取得了一些进展。今天我设法通过请求强制cookie,服务器终于验证了请求,但是我无法更新cookie并将经过身份验证的 cookie 传输到接下来的几页。
'post form data to page
strUrl = "https://e926.net/user/authenticate"
webRequest2 = HttpWebRequest.Create(strUrl)
webRequest2.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
webRequest2.AllowAutoRedirect = True
webRequest2.Method = WebRequestMethods.Http.Post
webRequest2.ContentType = "application/x-www-form-urlencoded"
webRequest2.CookieContainer = cookies
webRequest2.ContentLength = postData.Length
requestWriter = New StreamWriter(webRequest2.GetRequestStream)
requestWriter.Write(postData)
requestWriter.Close()
Dim response2 As HttpWebResponse = CType(webRequest2.GetResponse(), HttpWebResponse)
Dim strCookies2 As String = response2.Headers("Set-Cookie")
MsgBox(strCookies2)
strCookies2 = System.Text.RegularExpressions.Regex.Split(strCookies2, "((e926=.*))")(1)
strCookies2 = strCookies2.Split(";")(0)
strCookies2 = strCookies2.Replace("e926=", "")
cookie.Name = "e926"
cookie.Value = strCookies2
cookie.Domain = ".e926.net"
cookie.HttpOnly = True
cookie.Path = "/"
cookies.Add(cookie)
'recieve authenticated cookie
webRequest2.GetResponse().Close()
这是实际提交登录详细信息并处理实际登录请求的页面代码,我可以在 Fiddler 中看到发送了 'user' cookie 并更新了 'e926/auth' cookie,但我一直无法从标题或我尝试过的任何其他方法获取更新的 cookie..
该页面是 PHP 并且不允许“GET”请求,当然这些也无济于事,因为 cookie 似乎从未正确传输,并且必须根据请求更新 cookie。
所以我的问题是,如何从 VB.NET 中的页面获取更新的 cookie?
【问题讨论】: