0

Trying to determine if a file exists on the server using an MSXML2.XMLHTTP request. It works most of the time but every once in a while fails with "Operation timed out". At most, there error condition kicks in once and theh it returns to working normally. Any ideas?

 Public Function InputFileThere(myUrl As String) As Boolean
 Dim myLine As String
 Dim numTimes As Long
 Dim MyRequest As Object
 Dim urlExists As Boolean
 numTimes = 0
 urlExists = False
 Dim dirName As String
 Dim userName As String
 Dim passWord As String
 userName = “******”
 passWord = “******”
 On Error GoTo errorPart
 startHere:
 Set MyRequest = CreateObject("MSXML2.XMLHTTP")
 MyRequest.Open "HEAD", myUrl, False, userName, passWord
 MyRequest.send
 If MyRequest.StatusText = "OK" Then urlExists = True
 GoTo finHere
 errorPart:
 Set MyRequest = Nothing
 numTimes = numTimes + 1
 myLine = " Right now " & Format(Now(), "hh:mm:ss") & " there was an error , numTimes = " &    CStr(numTimes) & " Err Description = " & Err.Description
Application.StatusBar = myLine
Application.Wait (Now() + TimeValue("00:01:00"))
GoTo startHere
finHere:
InputFileThere = urlExists
Set MyRequest = Nothing
End Function
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
DrIzzy
  • 1
  • 1
    Seems like it would be difficult for anyone here to diagnose the problem - maybe you're making too many requests and the server is throttling you, or something else is blocking the request. Without knowing anything about the other end of the process, or what kind of load you're placing on it, it's difficult to make any guesses. – Tim Williams Mar 27 '19 at 19:54
  • You might want to check the HTTP status code rather than just looking at the status text. Check the value of `MyRequest.Status` against the details [here](https://tools.ietf.org/html/rfc7231#section-6.1) – barrowc Mar 27 '19 at 23:58
  • Thanks, I'll check that! – DrIzzy Mar 28 '19 at 12:36

0 Answers0