We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

Igor Kaplanov's avatar
Igor Kaplanov
Explorer | Level 3
4 years ago

VBA Request: HTTP status code 400

I have one macro that I used to test access to https://www.dropbox.com/ and it worked for three years. But, about December 15-16, it stopped: it always gives out a HTTP status code = 400!
It reacts normally to a dozen other services. I've been fighting for 5 days, friends helped, but... Can you share your ideas?

 

Here is the function ('the function checks for access to the URL $ resource (file or directory)
'returns the server response code (number), or 0 if the link is invalid
'(200 - resource available, 404 - not found, 403 - no access, etc.):

Public Function GetURLstatus(ByVal URL$) As Long

On Error Resume Next: URL$ = Replace(URL$, "\", "/")
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", URL, "False"
xmlhttp.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
xmlhttp.send
GetURLstatus = Val(xmlhttp.Status)
Set xmlhttp = Nothing
End Function
a fragment of a macro where this function is used:

URL$ = "https://dropbox.com/" '
directory link
If GetURLstatus(URL$) = 200 Then........



or:
MsgBox GetURLstatus(URL$), vbInformation, URL$

 

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    Hi Igor Kaplanov,

    Are you sure for the validity of link(s) in use? 🧐 What's going on when you try the same link(s) in a browser' incognito window? 🤔

    Hope this gives some direction.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    I recommend checking the body of the error response. It may contain a more useful error message or error page.

     

    For instance, the Dropbox web site recently dropped support for Internet Explorer 11, so if your HTTP client is setting a User-Agent that appears to be Internet Explorer 11, the Dropbox web site will now return an error page indicating that it is no longer supported.

     

    In that case, you could fix this by updating your code to not set a User-Agent string that appears to be Internet Explorer. (I can't provide support for VBA or Microsoft.XMLHTTP, but you might be able to set the "User-Agent" header via the "xmlhttp.setRequestHeader" method, like you're using to set your "If-Modified-Since" header.)