0

VB2012: I'm trying to login to my company website to parse out some info. It has a typical page

portal.mycompany.com

which redirects eventually to

security.mycompany.com/login.jsp?TYPE=xxx&METHOD=GET&{more parameters}

and there we are presented with textboxes for user name and password. I have Fiddler running and am a little lost as to what to look for when setting up my POST. My example looks to be the same from various coding sites. I am mainly looking for help on what to look for in Fiddler to use as a basis for the POST request to login to my site programmatically.

I took a look at some of the Fiddler entries and added what I thought was the enrty with the credentials. But when i tried adding this to the POST request it just responded with the original page.

    Dim cookieJar As New Net.CookieContainer()
    Dim request As Net.HttpWebRequest
    Dim response As Net.HttpWebResponse
    Dim strURL As String

    Try
        'Get Cookies
        strURL = "http://portal.mycompany.com"
        request = Net.HttpWebRequest.Create(strURL)
        request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
        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 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"
        request.Method = "POST"
        request.AllowAutoRedirect = True
        request.CookieContainer = cookieJar

        Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
        writer.Write("email=username&pass=password") 'where do I get this in Fiddler?
        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("<title>MyCompany") = True Then
            'LOGGED IN SUCCESSFULLY
        End If

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
pnuts
  • 58,317
  • 11
  • 87
  • 139
sinDizzy
  • 1,300
  • 7
  • 28
  • 60
  • Does Fiddler state that you authenticate with a POST request? Your example URI suggests otherwise: `...&METHOD=GET&...` – Phylogenesis Oct 07 '15 at 15:32
  • Not being a Fiddler expert, what would I look for? I see maybe like 15 entries after I click on the Login button. – sinDizzy Oct 07 '15 at 15:35
  • You need to find the request in the list that actually includes your username/password. Then under request headers it should say either `GET /someurl HTTP/1.1` or `POST /someurl HTTP/1.1`. – Phylogenesis Oct 07 '15 at 15:37
  • OK Out of all the entries I see one with my credentials and the header has a POST /site/logform/log.ddd HTTP/1.1. Now here I am theorizing I look at TextView and use the entry there as my addition to the request? – sinDizzy Oct 07 '15 at 15:48
  • Yes. You'll also have to change your code to send the `POST` request to `/site/logform/log.ddd`, too – Phylogenesis Oct 08 '15 at 08:18
  • There are a few posts related to your problem in C#, are you interested in seeing those? http://stackoverflow.com/a/4740851/2455159 and http://stackoverflow.com/questions/11118712/webclient-accessing-page-with-credentials may get you started if you are willing to 'translate' to VB. – Stephan Luis Mar 16 '16 at 21:33

0 Answers0