1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Httpwebrequest ~ how can I fill out web forms?

Discussion in 'Visual Basic .NET' started by simpleonline1234, Aug 29, 2011.

  1. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    I am new to webrequesting and I'm 50% on webbrowser options. I know when using a webbrowser you would fill forms using the web element like ID or Tag, etc.
    How can I do the same thing using httpwebrequest?
    For example let's say I have a form that I am going to fill out...
    Name
    Password
    Street Address
    Telephone Number
    etc
    How would one go about filling these out if using the httpwebrequest option?

    Thanks
     
  2. scriptomania

    scriptomania Junior Member

    Joined:
    Dec 28, 2010
    Messages:
    127
    Likes Received:
    249
    Occupation:
    A full time pirate at sea
    Location:
    The European capital of politics
    Get a HTTP traffic listener (something like the HTTPFox addon for firefox), make some test requests and try to emulate the headers. Filling out forms is most probably a POST request. So get HTTPFox or liveHeaders or whatever, make a sample request to the server (as in go ahead and fill out the form and submit it to the server).

    Check out the headers that were sent to the server with HTTPFox and then replicate them programatically. In python it would look something like this:

    Code:
    hOpen = httplib.HTTPConnection("your server here")
    Header = construct your header here
    RequestString = construct your request string here (something like name=blabal&pass=blabla)
    hOpen.request("POST", "your target address here", Header, RequestString)
    and so on...
    Hope this helps you out.

    cheers
     
  3. Crazy

    Crazy Jr. Executive VIP

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    You can also use MITM tools like Charles for this sort of network traffic analysis. Or, if you want a lot of information and a more technical breakdown, get something like Wireshark.
     
  4. shudogg

    shudogg Regular Member

    Joined:
    Sep 23, 2008
    Messages:
    412
    Likes Received:
    153
    Occupation:
    Internet Marketing
    Location:
    Indiana
    Home Page:
    Open your browser, and while grabbing/sniffing/capturing the packets, do what your wanting your app to do. (Register, login, ect.). When you done, stop capturing, clear out any non related packets.

    Using HTTPWebRequest, build a POST request and response that submits your data. Read the response, analyze what you read, do something. For instance:

    Code:
    Try
                Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
                response.Method = "POST"
                request.Timeout = 30000
                Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
                Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
                Dim str As String = reader.ReadToEnd
    
                'Now the string str holds all the HTML code of the page after your POST
                'So what do you need to do? Analyze the response
    
                If str.Contains("Thank you for registering") Then
                    MsgBox("Account Created!")
                End If
           
    Catch
                  MsgBox("There was an error/exception thrown")
    End Try
    
    

    That is just an example.. but after the response, you could look through the "str" which is the response of the server held into a String. look for an image, or a link, whatever.. Or maybe the next step needing for the specific site is to then POST more data (ie: the next step of registration).. Each site is different, but this is a template... Ensure you use Try and Catch, or else when problems arise, your app will crash and burn. Try saves the program from fully crashing.. You can enhance the try statement by adding in more things, such as on an exception it tries again (ie: tries to login 3 times then fails)

    Hope this helps.. I suggest you learn also about the CookieJar, Headers, Credentials (to handle proxies and private proxies)