Spring: return @ResponseBody “ResponseEntity”
Instead of return new ResponseEntity<JSONObject>(entities, HttpStatus.OK); try return new ResponseEntity<List<JSONObject>>(entities, HttpStatus.OK);
Instead of return new ResponseEntity<JSONObject>(entities, HttpStatus.OK); try return new ResponseEntity<List<JSONObject>>(entities, HttpStatus.OK);
requests handles redirects for you, see redirection and history. Set allow_redirects=False if you don’t want requests to handle redirections, or you can inspect the redirection responses contained in the r.history list. Demo: >>> import requests >>> url=”https://httpbin.org/redirect-to” >>> params = {“status_code”: 301, “url”: “https://stackoverflow.com/q/22150023”} >>> r = requests.get(url, params=params) >>> r.history [<Response [301]>, <Response [302]>] … Read more
You may want to consider status code 429, defined in https://www.rfc-editor.org/rfc/rfc6585#section-4.
The correct response, when a server is unable to handle a request, is 503 Service Unavailable. When the condition is temporary, as it is in your case, you can set the Retry-After header to let the client know how long it should wait before trying again. However, this will not force the browser to perform … Read more
If you use HTTP authentication as defined by RFC 7235, 401 would be correct (for missing or incorrect credentials). Otherwise, use 403.
To answer your questions: How to deal with unauthorized requests? The way you described it is pretty much the recommended way for a RESTful service. As far as I can see there is absolutely nothing wrong with that. What WWW-Authenticate header should 401 responses supply? In general the WWW-Authenticate header tells the client what kind … Read more
Well, I think it’s up to you which error code you’ll use. But if the actual functionality of your API depends on a third-party API, I would consider using the HTTP code 503 Service Unavailable, because your service will be unavailable until the third-party API works, no matter what HTTP code the third-party API returned. … Read more
There is no HTTP status code 0. What you see is a 0 returned by the API/library that you are using. You will have to check the documentation for that.
The getcode() method (Added in python2.6) returns the HTTP status code that was sent with the response, or None if the URL is no HTTP URL. >>> a=urllib.urlopen(‘http://www.google.com/asdfsf’) >>> a.getcode() 404 >>> a=urllib.urlopen(‘http://www.google.com/’) >>> a.getcode() 200
I had this exact same problem; in order to make sure that the correct answer is not buried in the comments (as it was for me), I want to reiterate @Sprockincat’s comment: For me at least, it was indeed an issue with IIS Custom errors, and can be solved with: Response.TrySkipIisCustomErrors = true; @Sprockincat – … Read more