Jump to content

Error in WinHTTP request


Recommended Posts

I have a function:

FUNC GETHTML($URLINPUT)
$OHTTP=OBJCREATE("winhttp.winhttprequest.5.1")
$OHTTP.Open("GET",$URLINPUT)
$OHTTP.Send()
$HTMLSOURCE=$OHTTP.Responsetext
RETURN $HTMLSOURCE
ENDFUNC

I want this function return the string "Can't connect" when load fail but I don't known how to do that. When connect fail, autoit will says:

---------------------------

AutoIt Error

---------------------------

Line 2038 (File "D:\Vampire\Programs\Program\test.au3"):

$OHTTP.Send()

$OHTTP.Send()^ ERROR

Error: The requested action with this object has failed.

---------------------------

OK

---------------------------

Please help me how to known when it connect fail.

Link to comment
Share on other sites

Try this:

FUNC GETHTML($URLINPUT)
$OHTTP=OBJCREATE("winhttp.winhttprequest.5.1")
$OHTTP.Open("GET",$URLINPUT)
$OHTTP.Send()
if @error Then
    msgbox(64, "Cannot connect","Cannot Connect." & " or socket died!")

Else
$HTMLSOURCE=$OHTTP.Responsetext
RETURN $HTMLSOURCE
EndIf
ENDFUNC
[size="5"] [/size]
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...