Questions tagged [http-response-codes]

HTTP Response Codes indicate whether a specific HTTP requests has been successfully completed. Responses are grouped in five classes: informational responses, successful responses, redirections, client errors, and servers errors.

346 questions
3534
votes
22 answers

403 Forbidden vs 401 Unauthorized HTTP responses

For a web page that exists, but for which a user does not have sufficient privileges (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve? 401 Unauthorized? 403 Forbidden? Something else? What…
330
votes
7 answers

PHP: How to send HTTP response code?

I have a PHP script that needs to make responses with HTTP response codes (status-codes), like HTTP 200 OK, or some 4XX or 5XX code. How can I do this in PHP?
Paulo Coghi
  • 13,724
  • 14
  • 68
  • 90
232
votes
11 answers

What is "406-Not Acceptable Response" in HTTP?

In my Ruby on Rails application I tried to upload an image through the POSTMAN REST client in Base64 format. When I POST the image I am getting a 406 Not Acceptable Response. When I checked my database, the image was there and was successfully…
Cyber
  • 4,844
  • 8
  • 41
  • 61
134
votes
5 answers

RESTful Login Failure: Return 401 or Custom Response

This is a conceptual question. I have a client (mobile) application which needs to support a login action against a RESTful web service. Because the web service is RESTful, this amounts to the client accepting a username/password from the user,…
Matt
  • 1,996
  • 5
  • 18
  • 24
116
votes
5 answers

What is the correct HTTP status code to send when a site is down for maintenance?

Is there a HTTP status code to tell Google (and others) to go away, index me again later? Basically, one that semantically tells clients that the site is down for maintenance? The ones I have considered are 304 => Not modified 307 => Temporary…
alex
  • 479,566
  • 201
  • 878
  • 984
68
votes
6 answers

How long does Chrome remember a 301 redirect?

I have a new author site that I want to make available from a domain that I had previously used Apache rewriting to bounce traffic to my Amazon site, [R=301,L], which I want to serve up as my own site. I also have a new domain for the interim at…
68
votes
4 answers

What does the HTTP 206 Partial Content status message mean and how do I fully load resources?

I have some image tags on a site like this. When I try to load them they are only half loading. When I checked the request in the network console I see that the response is: 206 Partial Content I googled it and it says that…
prasadmsvs
  • 1,621
  • 4
  • 18
  • 31
57
votes
4 answers

Requests — how to tell if you're getting a success message?

My question is closely related to this one. I'm using the Requests library to hit an HTTP endpoint. I want to check if the response is a success. I am currently doing this: r = requests.get(url) if 200 <= response.status_code <= 299: # Do…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
47
votes
4 answers

Is there a website that returns 500 (and other) HTTP response codes for testing?

It's occurred to me that it would be useful to have a URL that would always return a 500, for the sake of testing client code that handles getting bad responses. And I can think of other projects that would benefit from URLs that would always return…
Mark
  • 1,746
  • 2
  • 18
  • 19
47
votes
2 answers

Signalling authentication failure in a RESTful API

I'm writing a small application which exposes a simple REST-ish HTTP API. I'm stuck trying to decide how to signal a failure due to a lack of authorization. The app does not have an API for authentication, but instead depends upon the presence of a…
j0ni
  • 473
  • 1
  • 4
  • 6
37
votes
1 answer

Setting Response.Status Generates "HTTP Status String is Not Valid" Exception

I'm writing an HTTP handler in ASP.NET 4.0 and IIS7 and I need to generate a file-not-found condition. I copied the following code from Mathew McDonald's new book, Pro ASP.Net 4 in C# 2010. (The response variable is an instance of the current…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
35
votes
4 answers

NSUrlConnectionDelegate - Getting http status codes

in iOS, how can I receive the http status code (404,500 200 etc) for a response from a web server. I am assuming it's in the NSUrlConnectionDelegate. Objective-C or Monotouch .NET answer ok.
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
24
votes
1 answer

REST API response in partial success

I have an API which does some bulk processing task. Let's say it does naming of some resource. I passed 7 request in bulk, out of which 5 updated successfully and 2 failed. My question is how to handle the response. With HTTP I can't return both…
bandi shankar
  • 597
  • 2
  • 6
  • 8
22
votes
1 answer

how to find response code after httparty form POST

I have made a POST to a site using Httparty with the following code: HTTParty.post("http://example.com", :body => application_hash.to_json, :headers => {'Content-Type' => 'application/json'}) How can I check what the response code was for this…
dan-mi-sun
  • 551
  • 2
  • 4
  • 18
21
votes
3 answers

How to test render status: 404 with Rails4 and RSpec when using rescue_from

I have a Rails4 application with a 'PagesController'. The show-method throws a customized Exception 'PageNotFoundError' when a Page is not found. On top of the controller I defined rescue_from PageNotFoundError, with: :render_not_found render not…
Nockenfell
  • 1,111
  • 1
  • 8
  • 14
1
2 3
23 24