(500)内部服务器错误在网站登录脚本上

时间:2012-11-14 13:29:09

标签: vb.net httpwebrequest httpwebresponse

嘿,我有一个脚本,我在互联网上找到,可以登录到Facebook这很好但现在我尝试在另一个网站登录我得到500错误。

    Dim cookieJar As New Net.CookieContainer()
    Dim request As Net.HttpWebRequest
    Dim response As Net.HttpWebResponse
    Dim strURL As String = "http://xtract.basdistributie.nl:4040/Account/LogOn"

       Try 
        request = Net.HttpWebRequest.Create(strURL)
        request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
        request.Method = "GET"
        request.CookieContainer = cookieJar
        response = request.GetResponse()

        For Each tempCookie As Net.Cookie In response.Cookies
            cookieJar.Add(tempCookie)
        Next

        'Send the post data now
        request = Net.HttpWebRequest.Create(strURL)
        request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
        request.Method = "POST"
        request.AllowAutoRedirect = True
        request.CookieContainer = cookieJar

        Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
        writer.Write("username=???????&password=????????")
        writer.Close()

        response = request.GetResponse()

        'Get the data from the page
        Dim stream As StreamReader = New StreamReader(response.GetResponseStream())
        Dim data As String = stream.ReadToEnd()
        response.Close()

        If data.Contains("BAS Distribution Xtract") = True Then
            MsgBox("ingelogd")
        End If
        MsgBox(data)
    Catch e As Exception
        If TypeOf e Is WebException AndAlso DirectCast(e, WebException).Status = WebExceptionStatus.ProtocolError Then
            Dim errResp As WebResponse = DirectCast(e, WebException).Response
            ' read the error response
            Using respStream As Stream = errResp.GetResponseStream()
                MsgBox(e.ToString)
            End Using
        End If
    End Try

错误消息找到响应= request.GetResponse()我已经尝试使用Fidler来获得更好的错误消息,但从未使用过这个。我也读过互联网上的错误是因为该网站是用asp而不是.net构建的,这是真的吗?

所有帮助赞赏

1 个答案:

答案 0 :(得分:1)

Facebook的登录机制不能与其他网站一起使用的原因是因为它们可能没有相同的登录表单参数。

以下是您应该如何进行(虽然此时无法准确回答)

  1. 使用浏览器导航至您要登录的网站
  2. 检查登录表单的HTML以获取实际的参数名称。例如,此网站可能使用“uname”而不是“username”等类似的内容。
  3. 编辑您的代码,为表单
  4. 上的每个输入POST一个值

    如果这不起作用:

    1. 安装WireShark或类似内容,以便您可以查看HTTP流量
    2. 使用浏览器导航到网站
    3. 使用浏览器登录并使用wireshark查看登录请求。请特别注意POST变量名称和值以及标题信息
    4. 根据需要更新您的脚本
    5. 如果您需要第4步的帮助,请编辑您的帖子以包含第3步中的信息。

      <强>的Wireshark

      以下是如何在此处使用wireshark的简要说明。我不会详细介绍过滤或类似的事情。您可以用眼睛过滤:P

      当您打开wireshark时,会显示一个接口列表。第1步是选择一个界面...

      • 如果您通过wifi连接选择其中一个wlan接口。希望只有一个。你可以依靠试错来获得正确的
      • 如果您通过网络电缆连接,请选择eth0。希望只有一个等等。

      如果界面列表没有显示,那么窗口左上角应该有一个看起来像打印机的图标。单击它将允许您选择界面(单击开始以开始捕获)。

      登录您的网站(使用您的浏览器),然后点击带有红色x的icno立即停止捕获。

      现在你需要找到正确的数据包......

      您感兴趣的协议是HTTP。您正在访问的域的名称可能会显示在信息列中。现在我只是假设它确实如此。如果它不只是说评论。此外,如果您看到SSL,那么这可能是无用的。我对ssl还不是很了解......

      好的,您现在可以识别发送到Web应用程序的数据包。找一个说POST的人,看看里面有什么。如果那是你的登录资料,那就是胜利。

      记下所有相关信息。

      现在,如果您使用您的应用程序重复整个过程尝试登录并找到该登录数据包,那么您可以发现差异。