Questions tagged [http-status-codes]

HTTP status codes are a set of standardized codes returned in an HTTP web response. Questions about why a service is (unexpectedly) returning a status code should not use this tag.

For a full list of the status codes see the HTTP 1.1 specification, WebDAV specification, RFC 6585, and the IANA list of status codes.

HTTP status codes have specific meanings which are outlined in the specification that they were created in. They can be used in contexts outside of what the specification states, but must adhere to any conditions that have been established in the specification.

1693 questions
68
votes
7 answers

Are the HTTP status codes defined anywhere in the iOS SDK?

Does anyone know if/where the HTTP status codes, as specified here, are defined in the iOS SDK? Or should I expect to manually re-define them in a constants file?
esilver
  • 27,713
  • 23
  • 122
  • 168
68
votes
9 answers

How to extract HTTP status code from the RestTemplate call to a URL?

I am using RestTemplate to make an HTTP call to our service which returns a simple JSON response. I don't need to parse that JSON at all. I just need to return whatever I am getting back from that service. So I am mapping that to String.class and…
john
  • 11,311
  • 40
  • 131
  • 251
68
votes
7 answers

How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

I'm trying to report on every HTTP status code returned from my webapp. However the status code does not appear to be accessible via the ServletResponse, or even if I cast it to a HttpServletResponse. Is there a way to get access to this value…
Seth Weiner
  • 2,999
  • 5
  • 26
  • 14
67
votes
6 answers

Which HTTP status code to use for required parameters not provided?

I have several pages designed to be called with AJAX - I have them return an abnormal status code if they can't be displayed, and my javascript will show an error box accordingly. For example, if the user is not authenticated or their session has…
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
64
votes
8 answers

HTTP 400 (bad request) for logical error, not malformed request syntax

The HTTP/1.1 specification (RFC 2616) has the following to say on the meaning of status code 400, Bad Request (§10.4.1): The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request…
Atif Aziz
  • 36,108
  • 16
  • 64
  • 74
62
votes
5 answers

HTTP status code for "no data available" from an external datasource

Scenario: A POST request is sent to process an order that will result in data retrieval from an external datasource. There are three possible results: The datasource returned data for the request No data was available for the request (this is…
Trey Hunner
  • 10,975
  • 4
  • 55
  • 114
61
votes
1 answer

What is the most appropriate HTTP status code to return if a required header is missing?

I read What HTTP status response code should I use if the request is missing a required parameter? but it did not specifically ask about headers and there didn't seem to be a consensus. The context of this question assumes successful authentication.…
57
votes
8 answers

Correct http status code for resource which requires authorization

There seems to be a lot of confusion about the correct http status code to return if the user tries to access a page which requires the user to login. So basically what status code will be send when I show the login page? I'm pretty sure we need to…
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
57
votes
5 answers

What is the Correct HTTP Status Code for a Cancelled Request

When a TCP connection gets cancelled by the client while making a HTTP request, I'd like to stop doing any work on the server and return an empty response. What HTTP status code should such a response return?
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
56
votes
5 answers

After a POST, should I do a 302 or a 303 redirect?

A common scenario for a web app is to redirect after a POST that modifies the database. Like redirecting to the newly created database object after the user creates it. It seems like most web apps use 302 redirects, but 303 seems to be the correct…
Kyle
  • 21,377
  • 37
  • 113
  • 200
53
votes
1 answer

HTTP status code for unaccepted Content-Type in request

For certain resources, my RESTful server only accepts PUT and POST requests with JSON objects as the content body, thus requiring a Content-Type of application/json instead of application/x-www-form-urlencoded or multipart/form-data or anything…
Jordan
  • 4,510
  • 7
  • 34
  • 42
52
votes
4 answers

HTTP Status Code for External Dependency Error

What is the correct HTTP status code to return when a server is having issues communicating with an external API? Say a client sends a valid request to my server A, A then queries server B's API in order to do something. However B's API is currently…
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
50
votes
3 answers

What are proper status codes for CORS preflight requests?

What status code should a well-written HTTP server return when it gets a CORS preflight (OPTIONS) request? 200, 204 or something else? Should the status code be different in case origin is allowed (and corresponding headers will be set) or not…
Andrej
  • 1,679
  • 1
  • 26
  • 40
50
votes
4 answers

HTTP Status Code for database is down

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…
Guy
  • 65,082
  • 97
  • 254
  • 325
49
votes
5 answers

Is it OK to return a HTTP 401 for a non existent resource instead of 404 to prevent information disclosure?

Inspired by a thought while looking at the question "Correct HTTP status code when resource is available but not accessible because of permissions", I will use the same scenario to illustrate my hypothetical question. Imagine I am building a a…
Day
  • 9,465
  • 6
  • 57
  • 93