2013-10-29 1 views
0

webrequest와 POST를 사용하여 웹 사이트에 로그인하려고합니다. 내가 사용했던로그인이 필요한 웹 사이트의 웹 요청

크롬의 게시되는 데이터를 보려면 요소를 검사 :

ret=%2Fro%2Findex.php&sha1=2254****79a19&summon=8b5df8dc0c10323669f43105848ad40b8953fc8e&username=gabriel.zanc&password=&login=Conectare 

나는 '소환 때문에 WebRequest 클래스로 로그인 할 수 없습니다 요청 헤더가이 정보를 포함 POST에 로그인시
'값은 다음과 같이 웹 페이지에서 html로 하드 코드됩니다.

그리고 모든 세션마다 변경됩니다.

SHA1 필드는 암호& 소환 SHA1에서 인코딩된다.

어떤 도움이나 올바른 방향을 가리켜 주시면 대단히 감사하겠습니다.

감사합니다.

나중에 :

Dim username As String = "accName" 
    Dim password As String = "pass" 
    Dim summon As String = "" 

    ' Connect to WebSite 
    Dim wbReq As Net.HttpWebRequest = DirectCast(Net.WebRequest.Create("http://www2.gpstracking.ro/ro/login.php?ret=%2Fro%2Findex.php"), Net.HttpWebRequest) 
    Dim wbResp As Net.HttpWebResponse = DirectCast(wbReq.GetResponse(), Net.HttpWebResponse) 
    Dim wbHCol As Net.WebHeaderCollection = wbResp.Headers 
    Dim wbCookieJar As New CookieContainer 
    wbReq.CookieContainer = wbCookieJar 
    Dim myStream As IO.Stream = wbResp.GetResponseStream() 
    Dim myreader As New IO.StreamReader(myStream) 
    Me.TextBox2.Text = myreader.ReadToEnd 
    Dim doc As New HtmlAgilityPack.HtmlDocument 
    doc.LoadHtml(Me.TextBox2.Text) 
    ' get summon value 
    For Each input As HtmlNode In doc.DocumentNode.SelectNodes("//input") 
     If input.Attributes("name").Value = "summon" Then 
      summon = input.Attributes("value").Value 
     End If 
    Next 
    'login 
    Dim sha1Obj As New System.Security.Cryptography.SHA1CryptoServiceProvider 
    Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(password + summon) 
    bytesToHash = sha1Obj.ComputeHash(bytesToHash) 
    Dim sha1 As String = "" 
    For Each b As Byte In bytesToHash 
     sha1 += b.ToString("x2") 
    Next 
    Dim postdata = System.Text.Encoding.Default.GetBytes("ret=%2Fro%2Findex.php&sha1=" + sha1 + "&summon=" + summon + "&username=" + username + "&password=&login=Conectare") 

    Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://www2.gpstracking.ro/ro/login.php"), HttpWebRequest) 
    postReq.Method = "POST" 
    postReq.KeepAlive = True 
    postReq.CookieContainer = wbCookieJar 
    postReq.ContentType = "application/x-www-form-urlencoded" 
    postReq.Referer = "http://www2.gpstracking.ro/ro/login.php?ret=%2Fro%2Findex.php" 
    postReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0" 
    postReq.ContentLength = postdata.Length 

    Dim postreqstream As Stream = postReq.GetRequestStream() 
    postreqstream.Write(postdata, 0, postdata.Length) 
    postreqstream.Close() 
    Dim postresponse As HttpWebResponse 

    postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse) 
    wbCookieJar.Add(postresponse.Cookies) 
    Dim logincookie = wbCookieJar 
    Dim postreqreader As New StreamReader(postresponse.GetResponseStream()) 

    Me.TextBox1.Text += postreqreader.ReadToEnd 

하지만에 loggin에 아니에요 기본적으로

답변

1

처음 포함 된 페이지를 얻을 수있는 웹 요청을 사용, 화면 스크랩 대해 얘기 :
나는이 시도. 숨겨진 소환 필드를 사용하면 HtmlAgilityPack과 같은 것을 사용하여 HTML을 구문 분석하고 게시물에 포함 할 값을 얻을 수 있습니다.

쿠키를 사용하는 인증 된 웹 사이트에서 작업 할 때 HttpWebRequest를 각 요청에 대해 쿠키 컨테이너에 첨부해야 각 후속 요청에서 인증 요청 흐름에 의해 반환 된 쿠키를 보장해야합니다.

+0

감사합니다. 나는 그것을 시도하고 돌아올 것입니다. –

관련 문제