【问题标题】:vb.net http post cookies errorsvb.net http post cookie 错误
【发布时间】:2013-02-13 06:50:34
【问题描述】:

我知道以前有人问过这个问题,我一直在寻找答案,但我是 Post 新手,我不知道出了什么问题,在某些网站上它运行良好,但是当我使用它访问大学的内部网时我不断得到:

需要使用 HTTP cookie 来验证授权信息

请告诉我哪里做错了,这是我的代码:

        Dim cookies = New  CookieContainer()  
        ServicePointManager.Expect100Continue = False
        Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://banapp01*******/PROD/twbkwbis.P_ValLogin"), HttpWebRequest)
        request.CookieContainer = cookies
        'Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
        'Dim cookieCount As Integer = cookies.Count
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0"
        request.Method = "POST"
        request.Referer = "http://banapp01.*******/PROD/twbkwbis.P_WWWLogin"
        request.ContentType = "application/x-www-form-urlencoded"
        Using requestStream = request.GetRequestStream()
            Using writer = New StreamWriter(requestStream)
                writer.Write("sid=" & TextBox1.Text & "&PIN=" & TextBox2.Text)
            End Using
        End Using

        Using responseStream = request.GetResponse().GetResponseStream()
            Using reader = New StreamReader(responseStream)
                Dim result = reader.ReadToEnd()
                RichTextBox1.Text = result
            End Using
        End Using

谁能告诉我怎么了?或者我需要如何正确工作? 我已经研究 Post and Get 5 天了,但仍然失败! 我只是希望我的项目是完美的:S

【问题讨论】:

    标签: .net vb.net http post cookies


    【解决方案1】:

    我猜你还没有发出一个返回 cookie 存储在 CookieContainer 中的请求。

    是否需要先调用某种登录 url 才能分配身份验证 cookie?

    【讨论】:

    • 好吧,我已经在不同的网站上测试过这段代码,它可以工作,但我仍然无法弄清楚为什么它不能在 Intranet 横幅上工作。我已经阅读了其他帖子的所有建议,但仍然无法使其发挥作用。
    • @SalemRady cookie 变量是否有任何项目?可以签入调试器或使用 .Count 属性
    • Duno 如果这些帮助:banapp01.blabla.edu.lb:0000/PROD/twbkwbis.P_ValLogin POST /PROD/twbkwbis.P_ValLogin HTTP/1.1 主机:banapp01.blabla.edu.lb:0000 用户代理:Mozilla/5.0(Windows NT 6.1;WOW64 ; rv:19.0) Gecko/20100101 Firefox/19.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US ,en;q=0.5 Accept-Encoding: gzip, deflate Referer: banapp01.blabla.edu.lb:0000/PROD/twbkwbis.P_WWWLogin Cookie: TESTID=set Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 22 sid=someid&PIN=某针
    • 如何(在哪里?)调用登录网址?在我的代码中将此请求放在哪里?
    • @SalemRady 在您尝试发布到您发布的代码中的 URL 之前,您将需要获取 cookie(可能来自登录)。您可能想查看使用 Fiddler 来监控流量以查看是否正在接收和发送回 cookie -fiddler2.com/fiddler2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多