Attckdog Posted August 3, 2011 Posted August 3, 2011 (edited) Found this script somewhere in the forums and have been using it for a while to test URL's for images before Uploading Product feeds. Since I upload a lot of images I wanted to Make a script.Part of the script makes sure I don't get any "image already exists with that name" issues.Func _UploadTester() $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") $sTestUrl = "http://image-host.com" $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 With $oHttpRequest .SetTimeouts($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout) .Open("GET", $sTestUrl) .Send Select Case .Status = 200;No problem! ConsoleWrite($sTestUrl & " Already Uploaded " & @CR) Case .Status = 404;Not found ConsoleWrite($sTestUrl & " Clear to Upload " & @CR) Case Else;Some other problem ConsoleWrite("An unexpected HTTP Status value was returned: " & .Status & @CR) EndSelect EndWith $oHttpRequest = "" EndFunc ;==>_UploadTesterFound this script somewhere in the forums and have been using it for a while to test URL's for images before Uploading Product feeds. Can't find the original poster so I can't give credit to him/her Sigh. The Problem is: I get an error about nested With's not being allowed. I was wondering if there was an ingenious way around that. Or would I have to come up with new way to test the responsiveness of a URL. Thanks !-AttckEdit-Found Where I got the Script. Edited August 3, 2011 by Attckdog A true renaissance man
Tvern Posted August 3, 2011 Posted August 3, 2011 (edited) It seems pretty clear that there are no nested with statements in the posted code. I guess you're calling _UploadTester() from within a with statement, but it would help if the code posted would actually reproduce the problem. I can see two ways around this: The first and preferred option would be to just take the With statements out of the function and specifying the object used explicitly like this: ;Old syntax: With $oHttpRequest .Send EndWith ;New syntax: $oHttpRequest.Send The other option would be to break up the first with statement into two seperate ones, and have the function call to _UploadTester() in between. Edit (Offtopic): It is a shame that With's can't be nested when in seperate functions. This syntax (luckily) does not work: $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") With $oHttpRequest _Send() EndWith Func _Send() .Send EndFunc $oHttpRequest = False So I see no reason why another With could not be started in a local scope. Edited August 3, 2011 by Tvern
Attckdog Posted August 3, 2011 Author Posted August 3, 2011 It seems pretty clear that there are no nested with statements in the posted code. I guess you're calling _UploadTester() from within a with statement, but it would help if the code posted would actually reproduce the problem. I can see two ways around this: The first and preferred option would be to just take the With statements out of the function and specifying the object used explicitly like this: ;Old syntax: With $oHttpRequest .Send EndWith ;New syntax: $oHttpRequest.Send The other option would be to break up the first with statement into two seperate ones, and have the function call to _UploadTester() in between. Yes sorry about not showing the entire script, it was getting late in my work day and didn't have the time to edit out all the business specific details. I can however tell you it is because I am using a while statement to call the function. so I get the No nested With statements. I was wondering if there was a way to not use a with statement and still use that process. Thanks for your awesome attempt with so little info. A true renaissance man
Attckdog Posted August 4, 2011 Author Posted August 4, 2011 Just in case anyone else ever has this issue or wants to use the same script Here's the work around I used. Got Help/Code From: DaleHohm(AutoIT Forums) And Tvern(AutoIT Forums) Func _UploadTester() ;Got Help/Code From: DaleHohm(AutoIT Forums) And Tvern(AutoIT Forums) ;Adjusted to Work with While Loops $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") $sTestUrl = "http://imagehost.vendio.com/" $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 $oHttpRequest.SetTimeouts($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout) $oHttpRequest.Open("GET", $sTestUrl) $oHttpRequest.Send If $oHttpRequest.Status = 200 Then;If URL exist then Image already uploaded ConsoleWrite($sTestUrl & " Already Uploaded " & @CR) EndIf If $oHttpRequest.Status = 404 Then;URL 404 means it isn't uploaded already Continue Script ConsoleWrite($sTestUrl & " Clear to Upload " & @CR) EndIf $oHttpRequest = "" ; clears var for next use EndFunc ;==>_UploadTester A true renaissance man
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now