locked
how to use httpwebrequest ,GET moehod to login this page..with username and password RRS feed

  • Question

  • i try to login to this page by webrequest by GET method but i failed to login...

      

       Dim CookieJar As New CookieContainer
                Dim req As HttpWebRequest = HttpWebRequest.Create("http://69.207.166.218/index.htm")
    
                Dim authInfo As String = "Polycom" + ":" + "46837"
                authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo))
                With req
                    ' .Timeout = 15
                    '   .Headers("Authorization") = "Basic " + authInfo
                    .Headers.Add("Authorization", "Basic UG9seWNvbTo0NjgzNw==")
                    '  .CookieContainer = CookieJar
                    '  .CookieContainer.Add(New Cookie("Authorization", authInfo))
    
                    .Method = "GET"
                    .Host = "69.207.166.218"
                    .Headers.Add("Accept-Language", "en-US,en;q=0.5")
                    .Headers.Add("Accept-Encoding", "gzip, deflate")
                    .Headers.Add("X-Requested-With", "XMLHttpRequest")
                    .Accept = "*/*"
                    .ContentType = "text/html"
                    .Referer = "http://69.207.166.218/"
                    '.Connection = "keep-alive"
                    .UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0"
    
                End With
                '  req.CookieContainer.Add(New Cookie("Authorization", authInfo))
                Dim text As String = ""
                Dim response As HttpWebResponse = Nothing
                response = DirectCast(req.GetResponse(), HttpWebResponse)
                Dim receiveStream As StreamReader = Nothing
    
                receiveStream = New StreamReader(response.GetResponseStream())
                Dim strOutput As String = receiveStream.ReadToEnd()
                receiveStream.Close()
                response.Close()
    
                TextBox1.Text = strOutput
                WebBrowser1.DocumentText = strOutput



    • Edited by 0tarek0 Monday, January 8, 2018 9:33 PM
    Monday, January 8, 2018 9:33 PM

All replies

  • What are the indicators on failure to login, is there an exception message.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, January 8, 2018 10:45 PM
  • Hi 0tarek0,

    I have tested your code, and can access this page. Do you have some error message or where do you have error message?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 9, 2018 9:49 AM
  • i want to login automatic without enter password manualy...
    i want to login to index page ...

    Tuesday, January 9, 2018 3:58 PM
  • i want to login automatic without enter password manualy...
    i want to login to index page ...
    Tuesday, January 9, 2018 4:00 PM
  • Hi 0tarek0,

    If you want to login in website automatically, you can assign value in WebBrowser1_DocumentCompleted event.

    Dim Elems As HtmlElementCollection
            Elems = WebBrowser1.Document.GetElementsByTagName("input")
            For Each elem As HtmlElement In Elems
                If elem.GetAttribute("name").Equals("password") Then
                    elem.SetAttribute("value", "Password123")
                End If
            Next
    
            Dim theElementCollection As HtmlElementCollection
            theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
            For Each curElement As HtmlElement In theElementCollection
                If curElement.GetAttribute("value").Equals("Submit") Then
                    curElement.InvokeMember("click")
                End If
            Next

    I find one thread about assign value, you can take a look:

    https://social.msdn.microsoft.com/Forums/en-US/b1273d78-d4af-49e0-9238-6f86e9952484/webbrowserdocumentallainvokememberclick?forum=Vsexpressvb

    Best Regards,

    Cherry

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 10, 2018 10:42 AM
  • i am very sorry of you.... i want this by webrequest method
    Saturday, January 13, 2018 12:38 PM