Jump to content

Winhttp filling out multi-page form


Recommended Posts

Hi all, question to those who are familiar with Winhttp, in particular _WinHttpSimpleFormFill()

I have a form that I fill out and submit using _WinHttpSimpleFormFill() which then returns a subsequent form based on the first form.

How do I then fill out the subsequent form?

#include "WinHTTP.au3"

$sFile = @ScriptDir & "\test.csv"

$sFileHTM = @ScriptDir & "\Form.htm"

$hSession = _WinHttpOpen('Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0'); create new session
$hConnect = _WinHttpConnect($hSession, "www.server.com") ; connect to server
$sHTM = _WinHttpSimpleFormFill($hConnect, "form.cfm", "name:CFForm_2", "name:FileContents", $sFile, "name:import_vendor", "Generic")

;HERE I NEED TO FILL OUT THE SECOND FORM THAT IS RETURNED IN $sHTM

If $sHTM Then
    MsgBox(64 + 262144, "Done!", "Will open returned page in your default browser now." & @CRLF & _
            "It should show array of uploaded files below the form.")
    $hFileHTM = FileOpen($sFileHTM, 2)
    FileWrite($hFileHTM, $sHTM)
    FileClose($hFileHTM)
    ShellExecuteWait($sFileHTM)
EndIf

Cheers!

Link to comment
Share on other sites

That's easy. Form-fill function accepts strings of forms (sources) also. You would do this:

include "WinHTTP.au3"

$sFile = @ScriptDir & "\test.csv"

$sFileHTM = @ScriptDir & "\Form.htm"

$hSession = _WinHttpOpen('Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0'); create new session
$hConnect = _WinHttpConnect($hSession, "www.server.com") ; connect to server
$sHTM = _WinHttpSimpleFormFill($hConnect, "form.cfm", "name:CFForm_2", "name:FileContents", $sFile, "name:import_vendor", "Generic")

;HERE I NEED TO FILL OUT THE SECOND FORM THAT IS RETURNED IN $sHTM

; You just have to check that form's action be full URL. If it's not then use StringReplace() or something similar on $sHTM to set it.
$hConnNew = $sHTM
$sHTM = _WinHttpSimpleFormFill($hConnNew, $hSession, ...) ; tada!


If $sHTM Then
    MsgBox(64 + 262144, "Done!", "Will open returned page in your default browser now." & @CRLF & _
            "It should show array of uploaded files below the form.")
    $hFileHTM = FileOpen($sFileHTM, 2)
    FileWrite($hFileHTM, $sHTM)
    FileClose($hFileHTM)
    ShellExecuteWait($sFileHTM)
EndIf

Just make sure "action" of the form that you fill is full address and not in form of "/whatever.asp". If it's relative address then you have to e.g. StringReplace() it before filling the form. Check for errors after calling form filling function.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...