0

我正在尝试使用用户名和密码打开一个外部网站。我有正确的凭据,但是当我尝试以下代码时,我收到“登录失败:未知用户名或密码错误”错误。

        Dim username As String = "username"
        Dim password As New System.Security.SecureString

        'Set value for SecureString type variable   
        Dim plainPassword As String = "pass"
        For Each c As String In plainPassword.ToCharArray
            password.AppendChar(c)
        Next c

        Dim IEprocess As System.Diagnostics.Process = New System.Diagnostics.Process
        IEprocess.StartInfo.FileName = "http://www.website.com/"
        IEprocess.StartInfo.UserName = username
        IEprocess.StartInfo.Password = password
        IEprocess.StartInfo.UseShellExecute = False
        IEprocess.Start()

有什么建议么?

4

1 回答 1

1

如果您想登录网站,我认为最好使用 HTTP 的 POST 方法,并且您必须定义您的登录页面参数用户和密码(Php、ASP.Net、JAVA 推荐可以使用操作方法)。

Dim PostData As String = "define your action login" 'example https://login.yahoo.com/config/login_verify2?&.src=ym,username and Password parameters
    Dim bytes() As Byte = ASCIIEncoding.UTF8.GetBytes(PostData)
    Dim httpReg As HttpWebRequest = WebRequest.Create("http://www.website.com/")
    httpReg.Method = "POST"
    httpReg.KeepAlive = True
    httpReg.CookieContainer = mainCookie
    httpReg.ContentType = "application/x-www-form-urlencoded"
    httpReg.Referer = "http://www.website.com/index.html"
    httpReg.ContentLength = bytes.Length
    Dim DtStream As Stream = httpReg.GetRequestStream()
    DtStream.Write(bytes, 0, bytes.Length)
    DtStream.Close()
    Dim httpResponse As HttpWebResponse
    httpResponse = httpReg.GetResponse()
    mainCookie.Add(httpResponse.Cookies)
    Dim reader As New StreamReader(httpResponse.GetResponseStream())
    Dim strSource As String = reader.ReadToEnd
    If strSource.Contains("Selamat Datang") Then
        MessageBox.Show("Sukses Login")
    Else
        MessageBox.Show("Gagal Login")
    End If

参考文章: http ://tech.reboot.pro/showthread.php?tid=61

于 2013-02-08T02:06:54.183 回答