Jump to content
Sign in to follow this  
mpower

Winhttp filling out multi-page form

Recommended Posts

mpower

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!

Share this post


Link to post
Share on other sites
trancexx

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
  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
mpower

awesome, thanks so much!!

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Surya
      By Surya
      Hi everyone its been loooong since I posted here 
      I have been trying to convert this curl executable parameters into autoit using the winhttp com object;
      curl -F data_file=@my_audio_file.mp3 -F model=en-US "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4jdsgjhgghstOGU5YS00OWFhLWghdgjshgdhbshj017###" any ideas guys
       
      PS: I am excited to post here after a looong time
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • jasontj
      By jasontj
      Hello.  I'm working on converting another script from IE to Firefox.  I can't seem to get a handle on the field "Defendant" to fill in a last, first name on this page:
      http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal
      I also can't seem to submit the form.   I've tried the code below... stuff may be commented out that I have tested.
       
          _FFOpenUrl("http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal")    
          _FFLoadWait()
          $oTextFN = _FSObjGet("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_ContentPlaceHolder2_tabSearch_tabCriminal_txtCrimDefendant", "ID")
          
          _FFObj($oTextFN, "value", "Smith, John")    
          $subButton = _FFObjGet("ctl00$ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder2$ContentPlaceHolder2$btnSearch", "name")
          _FFClick($subButton)
          _FFLoadWait()
          
      ;    _FFFormSubmit()
      ;    _FFLoadWait()
       
      Any help from the experts on here would be greatly appreciated.  
       
      Jason
       
       
       
       
    • Ascer
      By Ascer
      Hello
      Opertation Sys: Win7 x64
      Problem: Connecting to webs using TLS 1.1 +
      Description: WinHttp.WinHttpRequest.5.1 using TLS 1.0 by default, i need higher version to connect into some webs.
      Dim $oHttp = ObjCreate("WinHTTP.WinHTTPRequest.5.1") $oHttp.open ("GET", "https://howsmyssl.com/a/check", False) $oHttp.Option(9) = 128 ; 128 - TLS 1.0, 512 - TLS 1.1, 2048 - TLS 1.2, 2056 - TLS 1.1 & TLS 1.2 $oHttp.Send ConsoleWrite($oHttp.responseText & @CRLF) ; at end of the respond you can check your TLS version. Mine is: {"tls_version":"TLS 1.0","rating":"Bad"} Error: $oHttp.Option works only with parameter 128 (TLS 1.0) other values make error {Bad parameter}
      Additional: I've done this tutorial about enabling TLS in registry: <link>
      Thanks for support.
      Ascer
    • islandspapand
      By islandspapand
      Hi All
      i am currently trying to add a function to my project that can send SMS, i have gone with Twilio for the sms service that use a REST API.
      I have never worked with an API before, and could use some help.
      I can get my function working with using cURL.exe and copy past command from the website with the following code. And thats great unfortunately i am have issue with character like æøå when sending a SMS appears like a box or ?. this does not happen if i do it from the website so it looks like a Unicode issue in curl.exe.
      I have done some searching on the forum and understand that i should be able to implement this curl command with the WinHTTP UDF from @trancexx so i don't need a third part exe and it might fix my charater issue.
      Unfortunately i really don't understand how i am to change curl commands to the WinHTTP and i was hoping some good maybe give me an example i could learn from.
      Thanks in advanced
      i have removed the AuthToken number from the script.
      _SendSMS("00000000","SomeOne","SMS body info") Func _SendSMS($SendTo,$SendFrom,$Msgtxt) $AccountSID = "ACbb765b3180d5938229eff8b8f63ed1bc" $AuthToken = "Auth Token number" $Data = '"https://api.twilio.com/2010-04-01/Accounts/'&$AccountSID&'/Messages.json"'& _ '-X POST \ --data-urlencode "To=+45'&$SendTo&'" \ --data-urlencode "From='&$SendFrom&'" \ --data-urlencode "Body='&$Msgtxt&'" \ -u '&$AccountSID&':'&$AuthToken&'' ShellExecute(@ScriptDir&"\curl.exe","-k "&$Data) ;~ curl 'https://api.twilio.com/2010-04-01/Accounts/ACbb765b3180d5938229eff8b8f63ed1bc/Messages.json' -X POST \ ;~ --data-urlencode 'To=+4500000000' \ ;~ --data-urlencode 'From=Reception' \ ;~ --data-urlencode 'Body=Test Body' \ ;~ -u ACbb765b3180d5938229eff8b8f63ed1bc:[AuthToken] EndFunc  
       
×