【问题标题】:VB.NET Update Cookies from POSTVB.NET 从 POST 更新 Cookie
【发布时间】: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?

【问题讨论】:

    标签: vb.net cookies


    【解决方案1】:

    我所要做的就是将“自动重定向”从“真”更改为假,它会强制从“身份验证”页面而不是“主页”页面收集 cookie。

    【讨论】:

      猜你喜欢
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      相关资源
      最近更新 更多