Jump to content

Posting form stopped working


Recommended Posts

One of my scripts has stopped working after being forced to rebuild my machine and installing the lastest version of AutoIt (v3.3) and I cant figure out how to fix it.

I have a script that posts form data to a url, I use the code in many of my scripts and the compiled versions still works. If I run or recompile the same code it now fails when trying to post the data.

It fails at $oHttpRequest.Send ($PostData)

C:\Program Files\AutoIt3\Include\scriptlog.au3 (19) : ==> The requested action with this object has failed.:

$oHttpRequest.Send ($PostData)

$oHttpRequest.Send ($PostData)^ ERROR

ERROR isnt very specific so Im not sure why it wont work when the compiled versions still work. Im assuming something has changed between versions of AutoIt.

#include <scriptlog.au3>

$begin = TimerInit()
$var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wuauserv", "Start")
If $var <> 2 Then
   ; set it
    RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wuauserv", "Start", "REG_DWORD", "2")
EndIf
postit("AutoUpdateSRV","completed",$var,$begin)

#include <Array.au3>

FUNC postit($name,$val,$notes,$installtime)
  $oMyError = ObjEvent("AutoIt.Error","nothing"); Install a custom error handler 
  $ResolveTimeout = 5000
  $ConnectTimeout = 5000
  $SendTimeout = 5000
  $ReceiveTimeout = 5000
  $sUrl = "https://www.myurl.com:444/log.asp"
  $PostData = "name=" & urlencode($name)
  $PostData = $PostData & "&PC=" & @ComputerName
  $PostData = $PostData & "&status=" & urlencode($val)
  $PostData = $PostData & "&notes=" & urlencode($notes)
  $PostData = $PostData & "&installtime=" & $installtime
  $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP")
  $oHttpRequest.Open ("POST", $sUrl,True)
  $oHttpRequest.setRequestHeader  ("Content-Type", "application/x-www-form-urlencoded")
  $oHttpRequest.setRequestHeader  ("Connection", "Keep-Alive")
  $oHttpRequest.Send ($PostData)
  sleep(1000)
  $oHttpRequest = ""
EndFunc

func urlencode($text)
    Local $splitted = StringSplit($text,"")
    for $i = 1 to $splitted[0]
        if $splitted[$i] = "-" or $splitted[$i] = "_" then continueloop
        if $splitted[$i] = " " then 
            $splitted[$i] = "+"
        else
            $splitted[$i] = "%" & Hex(Asc($splitted[$i]),2)
        endif
    next 
    return _ArrayToString($splitted,"",1)
endfunc

Any help is appreciated.

Link to comment
Share on other sites

Sorry everyone, this was my fault. When I rebuilt my PC, I had restored an old version of my custom include. Once I restored a current version, the problem went away. Since it was in include, that is why even old script where failing.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...