determining 404
Dave Cragg
dcragg at lacscentre.co.uk
Mon Apr 26 17:41:32 EDT 2004
At 3:59 pm -0500 26/4/04, Jim wrote:
>On Apr 26, 2004, at 2:40 PM, Dave Cragg wrote:
>
>> I'm not sure if this is exactly what you want, but if you check
>>the result after an http url call (get, post, etc.) it will contain
>>the word "error" followed by the status code and the status message
>>returned by the server (unless the call succeeded in which case the
>>result will return empty.) Typically, for a 404 status code, the
>>result will contain "error 404 File not found". You can't rely on
>>the consistency of the message (it can vary by server, script, etc.
>>and is intended to be human readable), but the status code will
>>always be word 2 of the result.
>>
>
>A server can be set up to deliver a custom page (rather than generic
>html reply) for 404. I did a quick test on a WebStar server, having
>set up a custom page for errors. It did, indeed, report a 404, but
>it said "OK", too...
>
>HTTP/1.1 404 OK
>
>So, you'll want to check out word 2 of libURLLastRHHeaders() to see
>if it's truly a 404.
You can still check word 2 of the result and get the same
information. When you do a "get url" and there is a 404 response, the
html page (custom or otherwise) will be returned in the "it"
variable, and the response code and message will be returned in "the
result" following the word "error".
So you can do something like this:
get url "http://whatever.com/some.html"
if the result is not empty then
switch word 2 of the result
case 404
# whatever
break
case 403
#whatever
break
default
#whatever
end switch
else
#do something with "it"
end if
Note that if you are using "load" instead of "get", and an error
occurs such as a 404 response, to get the status code you should use
libUrlErrorData(<url>). libUrlLastRHHeaders() won't be reliable in
this case as another load request may have been processed by the time
the one you are concerned with returns.
See here for more info:
<http://www.runrev.com/resources/liburl/liburldoc.shtml#libUrlErrorData>
Cheers
Dave
More information about the use-livecode
mailing list