http-status-codes

How to extract HTTP status code from the RestTemplate call to a URL?

拈花ヽ惹草 提交于 2019-11-29 15:53:52
问题 I am using RestTemplate to make an HTTP call to our service which returns a simple JSON response. I don't need to parse that JSON at all. I just need to return whatever I am getting back from that service. So I am mapping that to String.class and returning the actual JSON response as a string. RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.getForObject(url, String.class); return response; Now the question is - I am trying to extract HTTP Status codes after

406 Not Acceptable error GET parameter issue?

喜夏-厌秋 提交于 2019-11-29 13:02:13
Can anyone please tell me why the following URL returns a 406 error: http://kolek.to/functions/remote-upload.php?url=http%3A%2F%2Fben-major.co.uk%2Fhosting%2Fbm-equipment%2Faxe-2.jpg&item_id=2 Removing the ?url= parameter seems to make everything fine: http://kolek.to/functions/remote-upload.php?item_id=2 For your reference, the content of remote-upload.php is as follows: <?php require_once('../models/api.php'); $request_url = urldecode($_REQUEST['url']); $item_id = $_REQUEST['item_id']; echo $item_id; ?> I think that this is due to the security filter from your server (I see in the response

HTTP status code for missing authentication

故事扮演 提交于 2019-11-29 11:11:00
问题 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? 回答1: 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) 回答2: 403 I believe

Jquery $.ajax statusCode Else

a 夏天 提交于 2019-11-29 10:58:53
问题 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"

How can I get the IIS substatus code from an Exception?

寵の児 提交于 2019-11-29 10:49:49
I'm handling exceptions with an HttpModule in a manner such as this: int errorCode = 500; HttpApplication httpApp = (HttpApplication)sender; try { if (httpApp.Server != null) { Exception ex; for (ex = httpApp.Server.GetLastError(); ex != null; ex = ex.InnerException) { try { HttpException httpEx = ex as HttpException; if (httpEx != null) errorCode = httpEx.GetHttpCode(); // ... retrieve appropriate content based on errorCode } catch { } } } For HTTP status codes (ex: 302, 404, 503, etc) everything works great. However, for IIS status codes (ex: 401.5, 403.4, etc), can GetHttpCode retrieve

Is returning HTTP 409 appropriate for a validation check?

谁都会走 提交于 2019-11-29 09:32:44
I have a service where some validation rules must be checked before a particular operation should be able to take place. For instance, the client should not generate printable reports if all of the validation rules are not being met. However, an individual client may not have all of the required information (that user may only be able to access a subset of the data that is used to determine validation success), so a request must be sent to the server: basically "is a thing valid between start and finish ". The response will either be some sort of token that indicates VALID: FEEL FREE TO

Appropriate HTTP status code for request specifying invalid Content-Encoding header?

做~自己de王妃 提交于 2019-11-29 09:04:42
What status code should be returned if a client sends an HTTP request and specifies a Content-Encoding header which cannot be decoded by the server? Example A client POSTs JSON data to a REST resource and encodes the entity body using the gzip coding. However, the server can only decode DEFLATE codings because it failed the gzip class in server school. What HTTP response code should be returned? I would say 415 Unsupported Media Type but it's not the entity's Content-Type that is the problem -- it's the encoding of the otherwise supported entity body. Which is more appropriate: 415? 400?

Setting HTTP Status in ASP.NET MVC controller results does not render view

痞子三分冷 提交于 2019-11-29 07:13:06
I have a custom ActionResult for returning certain HTTP Errors, like NotFoundResult and ForbiddenResult, they all derive from ViewResult. I use them for instances like short circuiting actions with a 404 if an entity was not found in the database during the course of an action. Within these result objects, I set the HTTP Status to the appropriate number. When I do that, the view that these ViewResults reference does not render. I have to leave the status as 200 OK in order for my view to be rendered. How do I set an appropriate status AND render a view in ASP.NET MVC 2.0? I have a custom

How to use HTTP status code symbols in RSpec?

蹲街弑〆低调 提交于 2019-11-29 06:14:03
问题 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

HTTP Status 202 - how to provide information about async request completion?

99封情书 提交于 2019-11-29 05:36:07
What is the appropriate way of giving an estimate for request completion when the server returns a 202 - Accepted status code for asynchronous requests? From the HTTP spec ( italics added by me ): 202 Accepted The request has been accepted for processing, but the processing has not been completed. [...] The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled . Here are some of thoughts: I have glanced at the max-age directive, but using