POST.NET中的VB.NET更新Cookie

时间:2014-10-16 01:13:36

标签: vb.net cookies

我最近几天一直在研究这个问题并最终取得了一些进展。今天我设法通过请求强制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中看到“用户”cookie已发送且“e926 / auth”cookie已更新,但我一直在无法从标题或我尝试的任何其他方法获取更新的Cookie ..

页面是PHP,不允许'GET'请求,当然这些也无济于事,因为cookie似乎永远无法正常传输,并且必须从请求中更新cookie。

所以我的问题是,如何从VB.NET中的页面获取更新的cookie?

1 个答案:

答案 0 :(得分:0)

我所要做的就是改变'自动重定向'来自' true'是假的,它强迫cookie从'#aut;'页面而不是' home'页。