开发者

HTTP Status codes for 'non-broken' url

开发者 https://www.devze.com 2023-01-30 00:57 出处:网络
I need to determine if a URL entered by a site user is not broken.Essentially, that means it delivers a page that an anonymous user can view.

I need to determine if a URL entered by a site user is not broken. Essentially, that means it delivers a page that an anonymous user can view.

I've seen examples that say "if url returns 200" or "if url does not return 404" as methods used. Say, for example, it returns 301 or 403. These are开发者_如何学JAVA largely similar (in the definition I'm using here) to 200 and 404 respectively.

What is the best way to test if a url is valid based on http status codes?


Anything above 400 denotes an "error". 300's are used for redirects.


A URL that returns a status code of just about anything in the 200 range, with probably an exception of 203.


You can see a list of status codes here : http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

From what program you see a site user enter the URL?


Whether or not the URI is "valid" can be tested syntactically. But it seems what you're interested in is testing the resource identified by the URI.

That is harder to answer, and depends on your use case. Just because you get a 404 doesn't mean you might not get a 200 tomorrow. Or vice versa. Or the server may have an error condition (5xx) which is temporary. And so on.

0

精彩评论

暂无评论...
验证码 换一张
取 消