http-status-codes

Which HTTP code to use, in a REST API, for a subresource if the parent resource doesn't exist?

﹥>﹥吖頭↗ 提交于 2019-12-10 17:29:35
问题 My team and I are coding a REST API, but some concepts are still not fully understood. In a given resource: objective/{id}/goal where goal is collection If the consumer tries to reach an objective that doesn't exist, the API will return status code 404 , pretty simple. ex: objective/999 returns 404 For some reason the consumer tries to fetch the goals from this non existing resource: ex: objective/999/goal returns ? Which is the most suitable code to return? I have a feeling that this should

Check HTTP Status Code in Rails

折月煮酒 提交于 2019-12-10 17:27:16
问题 Is there an easy way to check the status code of another website (e.g. http://google.com) in Ruby on Rails? Ideally, the list of URLs to check would be pulled from a DB and processed via CRON (or equivalent). 回答1: require 'net/http' http = Net::HTTP.new('www.google.com',80) response = http.request_get('/') p response.status Slightly more efficient (traffic wise) might be: response = http.request_head('/') p response.status Source: http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net

Check on the status code of url before redirect_to in controller rails

旧街凉风 提交于 2019-12-10 10:34:46
问题 I have action check_status in instances_controller , and I want to check on status code of URL before redirect_to it. if status_code is 200 redirect_to it, else go to view page. This is the pseudo-code of check_status action: def check_status if "http://www.web.com".status_code == 200 redirect_to "http://www.web.com" else #DO Nothing, and go to its view end end For example get '/about' => 'instances#check_status' , and i want to check if (web.com) get status=200 visit (web.com) 回答1: You can

WCF Silverlight service returns custom fault but as HTTP 500 response not 200

吃可爱长大的小学妹 提交于 2019-12-10 07:22:38
问题 It seems like I've been banging my head with custom faults in my Silverlight WCF service forever so I will happily DO MY BEST TO BUY A BEER for anyone who can help me solve this!!! After much pain I finally have my WCF service throwing custom errors ( ParameterValidationFault ) and using Fiddler I know that the service's response contains my serialized fault object, but the HTTP response code is 500, not 200, so the client starts throwing exceptions rather than reading the response. I know my

HTTP 401 Unauthorized when not using HTTP basic auth?

不想你离开。 提交于 2019-12-10 05:00:58
问题 When building a REST API that doesn't use HTTP basic authentication (but something else like an api-key) and the client provides invalid credentials, what HTTP Status Code are you supposed to return? 401 Unauthorized or 403 Forbidden? The IANA HTTP Status Code Registry lists RFC7235, Section 3.1 as responsible for "401 Unauthorized", where it states: The server generating a 401 response MUST send a WWW-Authenticate header field Does that mean that a REST API should only ever return a 401 when

IIS7 and HTTP status code handling

依然范特西╮ 提交于 2019-12-10 03:26:25
问题 I'm having a hardcore head-ache from trying to get complete programmatic control over rendering of an error in IIS7 (integrated mode). What I want to do is given an error (page not found, internal server error, not authenticated, etc), transfer the whole request to a custom ASPX or HTML (I prefer the latter) with the correct HTTP status code. What I want is IIS7 to don't give a crap about what I set the HTTP status code to. I don't want its error handling. When I set Response.StatusCode =

Get description for HTTP status code

随声附和 提交于 2019-12-10 01:12:00
问题 In ASP.NET you can set the Response.StatusCode to for example 404. Should the status line / description always be set? (to in this case "404 Page Not Found") How do you get the description if you only have the code (404)? Is this somewhere in the framework or do you manually have to hardcode the descriptions? 回答1: You can use the static method HttpWorkerRequest.GetStatusDescription for this. 回答2: If you need it at the same time you're pulling Response.StatusCode, you can get the description

Get status code http.get response angular2

折月煮酒 提交于 2019-12-09 14:45:44
问题 I need to get the status code of the following http call and return it as a string //This method must return the status of the http response confirmEmail(mailToken):Observable<String>{ return this.http.get(this.baseUrl+"users/activate?mailToken="+mailToken) .map(this.extractData) .catch(this.handleError); } thx! 回答1: Adding answer for versions of Angular >= 4.3 (including 9) with new HttpClient that replaces http import {HttpClientModule} from '@angular/common/http'; // Notice it is imported

Which HTTP status code to return when the DELETE operation is not allowed for particular reason

谁都会走 提交于 2019-12-09 14:19:45
问题 Assume that I have a resource (e.g: /api/shipments/100 ) which supports HTTP DELETE method. As you can understand from the URI itself, if a DELETE request is made against this URI, this resource will be removed. In my current scenario, the DELETE request can only be performed successfully if a certain condition is met as below: If the shipment state is not set to InTransit or Delivered. If there is a DELETE request against that URI and the above condition is not met, which HTTP status code

404 vs 403 when directory index is missing

让人想犯罪 __ 提交于 2019-12-09 10:38:37
问题 This is mostly a philosophical question about the best way to interpret the HTTP spec. Should a directory with no directory index (e.g. index.html) return 404 or 403? (403 is the default in Apache.) For example, suppose the following URLs exist and are accessible: http://example.com/files/file_1/ http://example.com/files/file_2/ But there's nothing at: http://example.com/files/ (Assume we're using 301s to force trailing slashes for all URLs.) I think several things should be taken into