vb.net 在 WinForms 网络浏览器中启用 cookie

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17309396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:02:18  来源:igfitidea点击:

Enable cookies in WinForms webbrowser

vb.netcookiesbrowser

提问by Ziad Ahmed

i was trying to make a bot for a facebook game .. the problem is that the user need to login to facebook . i tried to make this with httpwebrequest . everything went fine but i got an error saying my web browser doesn't support cookies

我试图为 facebook 游戏制作一个机器人.. 问题是用户需要登录到 facebook。我试图用 httpwebrequest 做到这一点。一切正常,但我收到一条错误消息,说我的网络浏览器不支持 cookie

here is the code i used for the httpwebrequest

这是我用于 httpwebrequest 的代码

 Dim postData As String = "lsd=AVrFBNXT&display=&enable_profile_selector=&legacy_return=1&next=&profile_selector_ids=&trynum=1&timezone=-120&lgnrnd=163248_FehM&lgnjs=1372203160&email=" & (TextBox1.Text) & "&pass=" & (TextBox2.Text) & "f&default_persistent=1"
    Dim tempcookies As New CookieContainer
    Dim encoding As New UTF8Encoding
    Dim byteData As Byte() = encoding.GetBytes(postData)
    Dim postreq As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://www.facebook.com/login.php"), HttpWebRequest)
    postreq.Method = "POST"
    postreq.KeepAlive = True
    postreq.CookieContainer = tempcookies
    postreq.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"
    postreq.ContentType = "application/x-www-form-urlencoded"
    postreq.Referer = "https://www.facebook.com/login.php"
    postreq.ContentLength = byteData.Length
    Dim postreqstream As Stream = postreq.GetRequestStream()
    postreqstream.Write(byteData, 0, byteData.Length)
    postreqstream.Close()
    Dim postresponse As HttpWebResponse
    postresponse = DirectCast(postreq.GetResponse, HttpWebResponse)
    tempcookies.Add(postresponse.Cookies)
    logincookie = tempcookies
    Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
    Dim thepage As String = postreqreader.ReadToEnd
    WebBrowser1.DocumentText = thepage

采纳答案by Andrea

Webbrowser control is essentially an embedded Internet Explorer and thus shares Internet Explorer's settings.

Webbrowser 控件本质上是一个嵌入式 Internet Explorer,因此共享 Internet Explorer 的设置。

If your IE has cookies enabled then your WebBrowser control has them enabled too and your problem could be elsewhere.

如果您的 IE 启用了 cookie,那么您的 WebBrowser 控件也启用了它们,您的问题可能出在其他地方。

To check your IE settings follow these steps:

要检查您的 IE 设置,请按照下列步骤操作:

  1. Choose "Internet Options" under the "Tools" menu on the IE;
  2. Select the "Privacy" tab.
  3. Click the "Advanced..." button in the "Settings" groupbox.
  4. Check the "Override automatic cookie handling" option.
  5. Check both "Accept" options.
  6. Click "OK"
  1. 在IE的“工具”菜单下选择“Internet选项”;
  2. 选择“隐私”选项卡。
  3. 单击“设置”组框中的“高级...”按钮。
  4. 选中“覆盖自动 cookie 处理”选项。
  5. 选中两个“接受”选项。
  6. 点击“确定”