1

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

这是我用于 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
4

1 回答 1

1

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

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

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

  1. 在IE的“工具”菜单下选择“Internet选项”;
  2. 选择“隐私”选项卡。
  3. 单击“设置”组框中的“高级...”按钮。
  4. 选中“覆盖自动 cookie 处理”选项。
  5. 检查两个“接受”选项。
  6. 点击“确定”
于 2013-06-29T14:46:01.510 回答