根据要求更改/更新Cookie值

时间:2018-08-21 17:15:48

标签: .net vb.net httprequest httpresponse

尝试更新网站上的现有Cookie。

这是我尝试过的:

 Private Sub UpdateCookie()
    Dim cookieContainer As CookieContainer = New CookieContainer()
    Dim CookieChange As Cookie = New Cookie("cookieName", "coookieValue", "/", "myurl.com")
    cookieContainer.Add(CookieChange)
    Dim request As HttpWebRequest = CType(WebRequest.Create("https://myurl.com/"), HttpWebRequest)
    request.CookieContainer = cookieContainer

    Dim response As System.Net.HttpWebResponse = request.GetResponse()
    Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
    Dim sourcecode As String = sr.ReadToEnd()
    TextBox1.Text = sourcecode
End Sub

0 个答案:

没有答案