http-status-codes

What is the appropriate HTTP status code response for a general unsuccessful request (not an error)?

泄露秘密 提交于 2019-12-17 10:22:51
问题 I'm creating a RESTful API that will process a number of user interactions, including placing orders using stored credit cards. In the case of a successful order, I'm returning a 200 OK, and in the case where the order request is malformed or invalid I'm returning a 400 Bad Request. But what should I return if there is a problem during the actual processing of the order? Client POSTS order to server for a user resource. If user does not exist, 404 Not Found is returned. Order format and

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

萝らか妹 提交于 2019-12-17 04:01:57
问题 What is the best way to see a URL exists and the response is not a 404 ? 回答1: 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

How do I resolve a HTTP 414 “Request URI too long” error?

北城以北 提交于 2019-12-17 02:11:36
问题 I have developed a PHP web app. I am giving an option to the user to update multiple issues on one go. In doing so, sometimes the user is encountering this error. Is there any way to increase the lenght of URL in apache? 回答1: Under Apache, the limit is a configurable value, LimitRequestLine . Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf . If not, add a new line ( LimitRequestLine 10000 )

How to tell between a nonexistent service or a lack of a record?

落花浮王杯 提交于 2019-12-14 03:52:46
问题 I'm making some REST services, and as I'm implementing a GET request, I was debating about what I should do if there is no record there, for example /profile/1234 . Now, if you tried to use /profiles/1234 (note the s on profiles) it would definitely be a 404 code because that URL definitely isn't found. But when it comes to there just being no 1234 profile, I'm not sure what I should return. I don't want to return {} because that might give the impression there is a record with no data. But

PATCH to Rails app from iOS Client Returning Status 422

痞子三分冷 提交于 2019-12-13 21:25:11
问题 I have a Rails app with a Business model object with a count of visits . I have an iOS client that interacts with this Rails app using AFNetworking 2.0, and when a user taps a business in the app, it sends a PATCH to the Rails app, incrementing visits for that business. However, I'm getting a status code 422 "Unprocessable Entity" error back from the server, and the business's visits count on the server is not getting incremented. AFHTTPSessionManager - iOS - (NSURLSessionDataTask *

How to set http response header when php is used with g-wan

China☆狼群 提交于 2019-12-13 19:25:21
问题 I add the header function in the hello.php sample, as below: <?php header("xxxxx: yyyyy"); fwrite(STDOUT, "see headers.<br><br>Hello, PHP!<br>current working directory: ".getcwd()); exit(200); // return an HTTP code (200:'OK') ?> but there is no such header found in firebug. Who can explain how to add additional headers in php cli with gwan? 回答1: Thanks to Gil and Richard, Now, it is what i did according to your advices. PHP works in gwan with customized headers. <?php $output='See headers...

Appropriate HTTP Status Code for POST to create resource exceeding the limit

时光怂恿深爱的人放手 提交于 2019-12-13 08:18:29
问题 I have been playing with a REST API. I've found a bug, my POST request used to get response with HTTP-401 code. Even though, the resource was created. That's not how it should work. That made me think that this API was not the greatest API in the world. Then I fixed my request, everything looked fine but then the REST API returned HTTP-400 . The reason was "resource limit was exceeded". And here comes my question: What is the correct HTTP Status Code to handle the situation? I mean, the

Spring RestTemplate: How to reach state to check #is4xxClientError, instead of RestClientException 1st?

心不动则不痛 提交于 2019-12-13 03:24:47
问题 In my experience, after calling Spring's RestTemplate#exchange that subsequently receives '404 - Not Found' response, a RestClientException is thrown instead of returning a ResponseEntity that can have its status checked (i.e: with ResponseEntity#getStatusCode#is4xxClientError ). I don't understand why HttpStatus#is4xxClientError even exists if instead an Exception is thrown that prevents returning a ResponseEntity with HttpStatus to call # is4xxClientError on... I'm reasonably convinced what

Modify the Http Status Code text

流过昼夜 提交于 2019-12-12 18:24:30
问题 Question How to modify the Status Code text (description/title)? Example For example: I want to change 200 (Ok) to 200 (My Custom Text) Desciption I want to create a HTTP response with custom Status Code (unreserved) 431. I want to modify it's text: 200 (OK) 400 (Bad Request) 431 (My message here) I've tried: var response = new HttpResponseMessage() { StatusCode = (HttpStatusCode) 431, }; response.Headers.Add("Status Code", "431 My custom text"); // This throws error. 回答1: Just add

Custom exceptions to Http status codes in ASP.NET API

拥有回忆 提交于 2019-12-12 11:41:18
问题 I have a couple of custom exceptions in my business layer that bubble up to my API methods in my ASP.NET application. Currently, they all translate to Http status 500. How do I map these custom exceptions so that I could return different Http status codes? 回答1: This is possible using Response.StatusCode setter and getter. Local Exception handling: For local action exception handling, put the following inside the calling code. var responseCode = Response.StatusCode; try { // Exception was