2013-02-07 1 views
0

사용자 이름과 암호로 외부 웹 사이트를 열려고합니다. 올바른 자격 증명을 가지고 있지만 다음 코드를 시도 할 때 "로그온 실패 : 알 수없는 사용자 이름 또는 잘못된 암호"오류가 발생합니다.자격 증명이있는 Windows 양식에서 URL 열기

 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() 

의견이 있으십니까?

답변

1

웹 사이트에 로그인하려면 HTTP에서 POST Methode를 사용하는 것이 가장 좋으며 로그인 페이지 매개 변수 사용자 및 암호 (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 

referance에 Articel : http://tech.reboot.pro/showthread.php?tid=61

관련 문제