http-status-codes

HTTP status code for bad data

荒凉一梦 提交于 2019-12-03 23:13:30
问题 What HTTP status code should I return when a client posts bad data (e.g. a string when integer was expected)? I've been using 400 Bad Request, but as I read over the HTTP docs that seems more applicable to HTTP protocol errors. I'd like to use a status code so that Flash and AJAX clients can distinguish between success, bad data, and server error without having to parse a response. 回答1: This is exactly what 400 is for. Yes, it's used for bad HTTP protocol usage, but it's not exclusively for

How to check for an HTTP status code of 401?

有些话、适合烂在心里 提交于 2019-12-03 18:16:15
问题 In one of the answers that I have received here, I encountered a problem of not knowing how to pass automatically through "Google App Engines" my ID and a password to a website, on which I am a registered user and have an account. A suggestion was given to me to "check for an HTTP status code of 401, "authorization required", and provide the kind of HTTP authorization (basic, digest, whatever) that the site is asking for". I don't know how to check for status code. Can anyone, please, tell me

404 vs 403 when directory index is missing

删除回忆录丶 提交于 2019-12-03 13:11:59
This is mostly a philosophical question about the best way to interpret the HTTP spec. Should a directory with no directory index (e.g. index.html) return 404 or 403? (403 is the default in Apache.) For example, suppose the following URLs exist and are accessible: http://example.com/files/file_1/ http://example.com/files/file_2/ But there's nothing at: http://example.com/files/ (Assume we're using 301s to force trailing slashes for all URLs.) I think several things should be taken into account: By default, Apache returns 403 in this scenario. That's significant to me. They've thought about

HTTP 200 or 404 for empty list?

末鹿安然 提交于 2019-12-03 12:01:39
I know this is a fairly common question, but I haven't found an answer that satisfies me. I've been using django rest framework for a while now, but this is mostly irrelevant other than the example given. Its default behaviour is to return an HTTP 200 with an empty list resource when accessing a route with an empty list of items. E.g.: if we had a route such as /articles/ to access a list of articles but it contained no items we would get a response like the following json: {"count":0, "next":null, "previous":null, "items": []} Which is perfectly fine. We found the resource we were looking for

How return 304 status with FileResult in ASP.NET MVC RC1

十年热恋 提交于 2019-12-03 11:56:24
问题 As you may know we have got a new ActionResult called FileResult in RC1 version of ASP.NET MVC. Using that, your action methods can return image to browser dynamically. Something like this: public ActionResult DisplayPhoto(int id) { Photo photo = GetPhotoFromDatabase(id); return File(photo.Content, photo.ContentType); } In the HTML code, we can use something like this: <img src="http://mysite.com/controller/DisplayPhoto/657"> Since the image is returned dynamically, we need a way to cache the

What HTTP code to use in “Not Authenticated” and “Not authorized” cases?

可紊 提交于 2019-12-03 09:13:15
问题 I read that "401 Unauthorized" code must be used when a user: Is not logged, but login is required ("not authenticated"); Is logged, but his profile don't allow to see that url ("not authorized"); According to RFC, in both cases server must return 401 code. But I need to differentiate then in my ajax requests. Anybody have a tip to solve this? Note: I don't want to use 403 Forbidden code, because in 403 "Authorization will not help" , according to RFC. 回答1: You should pass a custom header in

Causing HTTP error status to be returned in WCF

江枫思渺然 提交于 2019-12-03 08:34:41
How can I get my WCF service to communicate errors in a RESTful manner? Specifically, if the caller passes invalid query string parameters to my method, I'd like to have a 400 or 404 HTTP error returned to the user. When I search for HTTP error status in relation to WCF, all I can find are pages where people are trying to resolve errors they're receiving. I'd rather not just throw a FaultException , because that gets converted to a 500 error, which is not the correct status code. I found a helpful article here: http://zamd.net/2008/07/08/error-handling-with-webhttpbinding-for-ajaxjson/ . Based

Redirecting with a 201 created

回眸只為那壹抹淺笑 提交于 2019-12-03 08:17:08
问题 Is there a way to redirect through a 201 answer? The RFC specifies that the newly created resource must be specified in the Location header, and I do specify it. I assumed that the browser would redirect but it doesn't, even if the page has no content. I want the user, after the POST action, to get redirected to the new resource. I'm therefore tempted to use 303 See Other but a 201 seems more appropriate. So, is there any way to automatically redirect popular browsers without user

Why does Python's urllib2.urlopen() raise an HTTPError for successful status codes?

此生再无相见时 提交于 2019-12-03 08:01:53
问题 According to the urllib2 documentation, Because the default handlers handle redirects (codes in the 300 range), and codes in the 100-299 range indicate success, you will usually only see error codes in the 400-599 range. And yet the following code request = urllib2.Request(url, data, headers) response = urllib2.urlopen(request) raises an HTTPError with code 201 (created): ERROR 2011-08-11 20:40:17,318 __init__.py:463] HTTP Error 201: Created So why is urllib2 throwing HTTPErrors on this

What HTTP Status Codes Should Programmers be Concerned With?

こ雲淡風輕ζ 提交于 2019-12-03 07:30:36
问题 So, if you look at the List of HTTP Status Codes, there are probably a number of them that would be useful while programming. The server might handle some things, like protocols, but a lot of these codes could be useful in telling the browser the actual status of the page. So, my question is which of these status codes should we be concerned with? Which should we be checking to send, and which ones will most likely never be used in regular application programming. If you are curious, this is