http-status-codes

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

泄露秘密 提交于 2019-11-26 19:17:59
问题 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

System.Net.WebException HTTP status code

Deadly 提交于 2019-11-26 19:16:20
问题 Is there an easy way to get the HTTP status code from a System.Net.WebException ? 回答1: 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 } } 回答2: By using the null-conditional operator ( ?. ) you can

Throw HttpResponseException or return Request.CreateErrorResponse?

一曲冷凌霜 提交于 2019-11-26 18:03:12
After reviewing an article Exception Handling in ASP.NET Web API I am a bit confused as to when to throw an exception vs return an error response. I am also left wondering whether it is possible to modify the response when your method returns a domain specific model instead of HttpResponseMessage ... So, to recap here are my questions followed by some code with case #s: Questions Questions regarding Case #1 Should I always use HttpResponseMessage instead of a concrete domain model, so that the message can be customized? Can the message be customized if you are returning concrete domain model?

What is the best way to check if a URL exists in PHP?

这一生的挚爱 提交于 2019-11-26 17:45:52
What is the best way to see a URL exists and the response is not a 404 ? You can use get_headers($url) Example 2 from Manual: <?php // By default get_headers uses a GET request to fetch the headers. If you // want to send a HEAD request instead, you can do so using a stream context: stream_context_set_default( array( 'http' => array( 'method' => 'HEAD' ) ) ); print_r(get_headers('http://example.com')); // gives Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT [Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux) [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT [ETag] => "3f80f

Response status code for searches in REST APIs

大城市里の小女人 提交于 2019-11-26 17:00:55
问题 Suppose, we have the following API: GET /api/guests/{id} GET /api/guests?name=dummy Which status code should I return when there are no guests matching criteria? I mean no guests with name dummy . Should it be 404 , 204 or 200 with an empty array? 回答1: I would return 200 with an empty array... Or a 204 (No Content) A 404 is when a resource isn't found. Your resource in this case is the collection of guests... which exists. 回答2: The proper status code for each situation Consider the following

PHP Get Content of HTTP 400 Response

落爺英雄遲暮 提交于 2019-11-26 16:45:01
问题 I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems. Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response. I really need a way

Why does Firebug show a “206 Partial Content” response on a video loading request?

删除回忆录丶 提交于 2019-11-26 16:25:49
问题 I have a bunch of html5 video elements, with their preload attribute set to "auto". They start loading just fine, but I think there might be a problem with their caching, because each time I reload the page (without clearing the cache), they start all over again. When I checked the Network panel in firebug, I noticed everything else (images and files) was giving me a "304 not modified" message as espected, while the videos (and audio) files were giving me a "206 partial content" message, in

Is it correct to return 404 when a REST resource is not found?

南笙酒味 提交于 2019-11-26 15:39:33
问题 Let's say I have a simple (Jersey) REST resource as follows: @Path("/foos") public class MyRestlet extends BaseRestlet { @GET @Path("/{fooId}") @Produces(MediaType.APPLICATION_XML) public Response getFoo(@PathParam("fooId") final String fooId) throws IOException, ParseException { final Foo foo = fooService.getFoo(fooId); if (foo != null) { return Response.status(Response.Status.OK).entity(foo).build(); } else { return Response.status(Response.Status.NOT_FOUND).build(); } } } Based on the code

What is correct HTTP status code when redirecting to a login page?

醉酒当歌 提交于 2019-11-26 15:15:53
问题 When a user is not logged in and tries to access a page that requires login, what is the correct HTTP status code for a redirect to the login page? I am asking because none of the 3xx response codes set out by the W3C seem to fit the requirements: 10.3.1 300 Multiple Choices The requested resource corresponds to any one of a set of representations, each with its own specific location, and agent- driven negotiation information (section 12) is being provided so that the user (or user agent) can

What&#39;s an appropriate HTTP status code to return by a REST API service for a validation failure?

为君一笑 提交于 2019-11-26 12:36:15
I'm currently returning 401 Unauthorized whenever I encounter a validation failure in my Django / Piston based REST API application. Having had a look at the HTTP Status Code Registry I'm not convinced that this is an appropriate code for a validation failure, what do y'all recommend? 400 Bad Request 401 Unauthorized 403 Forbidden 405 Method Not Allowed 406 Not Acceptable 412 Precondition Failed 417 Expectation Failed 422 Unprocessable Entity 424 Failed Dependency Update : "Validation failure" above means an application level data validation failure, i.e., incorrectly specified datetime, bogus