http-status-codes

HTTP Status Code for database is down

江枫思渺然 提交于 2019-11-27 22:56:44
问题 I have a page on my web site that reports on the health of the site and sets an HTTP 200 status code is everything is okay. This page is used by an external monitoring program to check that the site is up. When this page is hit, I make a very lightweight DB proc call to see if the DB is up and okay. If this fails, I want to return a meaningful HTTP error code to the monitor to let it know that all is not well. From what I can work out there's no HTTP status that says "a third party component

When is it appropriate to respond with a HTTP 412 error?

 ̄綄美尐妖づ 提交于 2019-11-27 22:41:20
It is unclear to me when you should and should not return a HTTP 412: Precondition Failed, error for a web service? I am thinking of using it when validating data. For example, if a client POST's XML data and that data is missing a required data element, then responding with a 412 and a description of the error. Does that align with the spirit of responding with an HTTP 412, or should something else be used (e.g. another http error code or web application exception)? If you look at RFC 2616 you'll see a number of request headers that can be used to apply conditions to a request: If-Match If

What's the appropriate HTTP status code to return if a user tries logging in with an incorrect username / password, but correct format?

末鹿安然 提交于 2019-11-27 22:40:06
A similar question is posted here: What's an appropriate HTTP status code to return by a REST API service for a validation failure? The answer in the thread above states that "For instance if the URI is supposed to have an ISO-8601 date and you find that it's in the wrong format or refers to February 31st, then you would return an HTTP 400. Ditto if you expect well-formed XML in an entity body and it fails to parse." However, what happens if the user submitted correctly formatted data? By this I mean, the user submitted a plain alphabetical string / text for the username and password (which is

how do I check an http request response status code from iOS?

梦想的初衷 提交于 2019-11-27 22:23:34
问题 I am sending an http request from iOS (iPad/iPhone) to my python google app engine server using the NSURLConnection and NSURLRequest classes. How do I read the response's status, i.e. the value set by app engine using response.set_status(200, message="Success") for instance? I'm not able to find where I can read these status codes once I receive the NSURLConnection's connectionDidFinishLoading delegate call on the client end. 回答1: The connection:didReceiveResponse: delegate method is called

HTTP status code for a partial successful request

邮差的信 提交于 2019-11-27 19:12:33
I have an application that sends messages to users. In a post request a XML string is transferred that consists of all the users that should receive that particular message. If any of the users in the list do not exist I give the list of missing users back to the client for further evaluation. Now I'm asking myself what would be the proper status code for the application saying that the request was accepted but there were things that couldn't be done. The problem would be avoided if it weren't allowed to include missing users in the list. Then the sending attempt would just get an 4xx error.

What http status code is supposed to be used to tell the client the session has timed out?

依然范特西╮ 提交于 2019-11-27 18:04:46
In a webpage, it uses YUI connection manager/datasource to send AJAX requests to the server, if the session (which contains the info on whether the user has been authenticated) has already timed out, those ajax responses that can only be viewed by authenticated users should return an http status code, telling the client that the session has already timed out, then the client either simply redirects him to the login page or asks him if he wants to extend the session. My question is that, in this situation, what http status code is the most appropriate to tell the client the session has timed

System.Net.WebException HTTP status code

拟墨画扇 提交于 2019-11-27 18:03:35
Is there an easy way to get the HTTP status code from a System.Net.WebException ? Maybe something like this... try { // ... } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { var response = ex.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); } else { // no http status code available } } else { // no http status code available } } Martin Liversage By using the null-conditional operator ( ?. ) you can get the HTTP status code with a single line of code: HttpStatusCode? status = (ex.Response as

HttpStatusCodeResult(401) returns “302 Found”

徘徊边缘 提交于 2019-11-27 18:02:10
问题 Using ASP.NET MVC 5, I would like to return appropriate HTTP status code for different scenarios (401 for user is not authenticated, 403 when user has no right for some resource, etc.), than handle them in jQuery. But the problem is, when I try to return 401, it always returns "302: Found". What is the trick for a custom status code, and why this doesn't work? public ActionResult My() { if (User.Identity.IsAuthenticated == false) { return new HttpStatusCodeResult(401, "User is not

HTTP Status 202 - how to provide information about async request completion?

扶醉桌前 提交于 2019-11-27 17:24:35
问题 What is the appropriate way of giving an estimate for request completion when the server returns a 202 - Accepted status code for asynchronous requests? From the HTTP spec ( italics added by me ): 202 Accepted The request has been accepted for processing, but the processing has not been completed. [...] The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the

In Python, how do I use urllib to see if a website is 404 or 200?

孤街醉人 提交于 2019-11-27 17:21:54
How to get the code of the headers through urllib? The getcode() method (Added in python2.6) returns the HTTP status code that was sent with the response, or None if the URL is no HTTP URL. >>> a=urllib.urlopen('http://www.google.com/asdfsf') >>> a.getcode() 404 >>> a=urllib.urlopen('http://www.google.com/') >>> a.getcode() 200 Joe Holloway You can use urllib2 as well: import urllib2 req = urllib2.Request('http://www.python.org/fish.html') try: resp = urllib2.urlopen(req) except urllib2.HTTPError as e: if e.code == 404: # do something... else: # ... except urllib2.URLError as e: # Not an HTTP