0

我有这个代码

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim logincookie As New CookieContainer


    Dim postData As String = "continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dheader%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F&service=youtube&uilel=3&dsh=-5804339713411277263&ltmpl=sso&hl=en_US&GALX=kpcgpuXEK94&pstMsg=1&dnConn=&checkConnection=youtube%3A4148%3A1&checkedDomains=youtube&timeStmp=&secTok=&Email=" & user_fb.Text & "&Passwd=" & pass_fb.Text & "&signIn=Sign+in&PersistentCookie=yes&rmShown=1"
    Dim tempCookies As New CookieContainer
    Dim encoding As New UTF8Encoding
    Dim byteData As Byte() = encoding.GetBytes(postData)


    Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://accounts.google.com/ServiceLoginAuth"), HttpWebRequest)
    postReq.Method = "POST"
    postReq.KeepAlive = True
    postReq.CookieContainer = tempCookies
    postReq.ContentType = "application/x-www-form-urlencoded"
    postReq.Referer = "https://accounts.google.com/ServiceLoginAuth"
    postReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko)"
    postReq.ContentLength = byteData.Length
    Dim postreqstream As Stream = postReq.GetRequestStream()
    postreqstream.Write(byteData, 0, byteData.Length)
    postreqstream.Close()
    Dim postresponse As HttpWebResponse

    logincookie = tempCookies
    postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
    tempCookies.Add(postresponse.Cookies)


    Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

    Dim thepage As String = postreqreader.ReadToEnd
    WebBrowser1.DocumentText = thepage


End Sub

试图制作一个用于 youtube 上传视频的工具,但是当我尝试登录时它似乎有一个 cookie 问题!

它说必须允许 cookie 运行此操作!如何启用 cookie?

4

3 回答 3

0
...

Dim galx As New Cookie
galx.Name = "GALX"
galx.Value = "something"
galx.Domain = ".google.com"
Dim postData As String = "GALX=something&continue=http%3A%2F......

...

tempCookies.Add(galx)

我正在搜索这个“youtube登录”的东西。我在 webbrowser1 上使用“grudolf”的代码收到了相同的消息。然后我在登录 youtube 时查看了 firefox 的“工具/开发者控制台”。有一个包含成员“ACCOUNT_CHOOSER”、“GALX”、“GAPS”等的 cookie 集合......当我添加一个名为“GALX”的 cookie 和任何 vale 并将其添加到帖子数据中时,结果还可以。我刚刚添加了代码。我希望它会有所帮助...

于 2014-04-02T16:45:50.793 回答
0

在开始时再定义一个 Cookie 容器:

Dim oRequestCookie As New CookieContainer

尝试添加

 CType(postReq, HttpWebRequest).CookieContainer = oRequestCookie 

当您定义 HttpWebRequest 参数时。最后,您可以像以前那样提取登录 cookie。干杯。

于 2013-04-04T11:23:29.893 回答
0

问题是您的推荐页面应该在用户机器 https://accounts.google.com/ServiceLoginAuth中放置一些 cookie

然后,当您尝试登录谷歌时,在您登录之前检查这些 cookie,现在谷歌会找到 cookie。解决方案是首先访问您的推荐页面并确保CookieContainer在该页面中使用,然后调用您的代码,它将 100% 工作。

尝试从逻辑上解决问题,然后考虑代码中的错误。

于 2013-07-05T17:53:40.640 回答