http-status-codes

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

ε祈祈猫儿з 提交于 2019-11-30 22:19:40
问题 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 timed out and they try to call one of the AJAX pages, it will return 401 Unathorized . I also have some return 500 Internal Server Error if something really odd happens server-side. What status code should I return if one of these pages was called

How to check if a webpage exists. jQuery and/or PHP

和自甴很熟 提交于 2019-11-30 20:32:05
I want to be able to validate a form to check if a website/webpage exists. If it returns a 404 error then that definitely shouldn't validate. If there is a redirect...I'm open to suggestions, sometimes redirects go to an error page or homepage, sometimes they go to the page you were looking for, so I don't know. Perhaps for a redirect there could be a special notice that suggests the destination address to the user. The best thing I found so far was like this: $.ajax({url: webpage ,type:'HEAD',error:function(){ alert('No go.'); }}); That has no problem with 404's and 200's but if you do

HTTP POST response Location header when creating multiple resources

笑着哭i 提交于 2019-11-30 19:05:51
The HTTP/1.1 standard states that if a POST operation results in the creation of a resource, then the response should include a Location header with the address of the new resource. If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section 14.30). and in section 14.30, For 201 (Created) responses, the Location is that of the new resource which was created by the request. Now suppose that my API allows batch creation of resources by

Ruby-on-Rails: How to get rid of “you are being redirected” page

一笑奈何 提交于 2019-11-30 17:15:30
I am overriding Devise's failure response so that I can set a 401 status code. However, when the user fails to sign in, they are redirected to a page with a "you are being redirected" link. If I remove this :status => 401 from the redirect it works fine. class CustomFailure < Devise::FailureApp def redirect_url new_user_session_url(:subdomain => 'secure') end def respond if http_auth? http_auth else store_location! flash[:alert] = i18n_message unless flash[:notice] redirect_to redirect_url, :status => 401 end end end edit Alternatively I would like to display the flash message and remain on

java.io.IOException: Server returned HTTP response code: 403 for URL [duplicate]

大兔子大兔子 提交于 2019-11-30 17:14:52
问题 This question already has answers here : 403 Forbidden with Java but not web browser? (4 answers) Closed last year . I want to open a link from url : "http://www.kohls.com/search.jsp?search=jacket&submit-search=web-regular", sometimes i get: java.io.IOException: Server returned HTTP response code: 403 for URL. But it's ok when open the url using browser. Below is part of my code: URL url = new URL("http://www.kohls.com/search.jsp?search=jacket&submit-search=web-regular"); InputStream is = url

HTTP Status 424 or 500 for error on external dependency

北城余情 提交于 2019-11-30 13:41:31
问题 I am trying to create a service that has 2 dependencies. One of the dependencies is internally managed while the 2nd requires an external http outbound call to a third party API. The sequence requires the updating the resource and then executing the http outbound call. So my question is, on the event of a failure on the 2nd step, what is the correct http status code to return? Should the response be 424 or 500 with a message body explaining the encountered error? 424: Method Failure -

Jquery $.ajax statusCode Else

陌路散爱 提交于 2019-11-30 10:56:58
In a jquery Ajax call I am currently handling statusCode of 200 and 304. But I also have "Error" defined" To catch any Errors that could come back. If there is a validation message related we return the status code of 400 - Bad Request. This then falls into the "Error" function before falling into the statusCode "400" function I had defined. Which means two actions happen. Ideally I would like to not define "Error" and "Success" and only define "statusCode" But what I need is to have a "Else" so that I don't need to declare every statusCode that exists only the 2-3 I want to handle differently

HTTP status code for missing authentication

梦想与她 提交于 2019-11-30 08:09:24
HTTP defines the status 401 Unauthorized for missing authentication, but this status only applies to HTTP authentication. What status should I return with a session cookie based system, when an unauthorized request happens? Formally, 403 Forbidden is the right response. It's defined as Authorization will not help and the request SHOULD NOT be repeated. The confusing part may be "Authorization will not help", but they really mean "HTTP authentication" (WWW-Authenticate) 403 I believe is technically correct (and probably most effective if you are implementing a custom API / protocol). 401 is not

How to use HTTP status code symbols in RSpec?

烈酒焚心 提交于 2019-11-30 05:52:14
I use HTTP status code symbols in code in a controller such as: render json: { auth_token: user.authentication_token, user: user }, status: :created or render json: { errors: ["Missing parameter."] }, success: false, status: :unprocessable_entity In the code of my request spec I also would like to use the symbols: post user_session_path, email: @user.email, password: @user.password expect(last_response.status).to eq(201) ... expect(last_response.status).to eq(422) However each test where I use the symbols instead of integers fails: Failure/Error: expect(last_response.status).to eq(:created)

HTTP status code for “no data available” from an external datasource

孤人 提交于 2019-11-30 05:43:27
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 viewed as an error) The datasource couldn't be accessed (may be down for maintenance) An obvious response for 1 is 200: OK or 201: Created (an entity is created from this request). What status codes would be appropriate for 2 and 3 ? Status codes I have considered: 503: Service Unavailable when datasource is down 500: Internal Server Error when datasource