http-status-codes

What is correct HTTP status code when redirecting to a login page?

依然范特西╮ 提交于 2019-11-27 10:38:13
When a user is not logged in and tries to access a page that requires login, what is the correct HTTP status code for a redirect to the login page? I am asking because none of the 3xx response codes set out by the W3C seem to fit the requirements: 10.3.1 300 Multiple Choices The requested resource corresponds to any one of a set of representations, each with its own specific location, and agent- driven negotiation information (section 12) is being provided so that the user (or user agent) can select a preferred representation and redirect its request to that location. Unless it was a HEAD

How do I choose a HTTP status code in REST API for “Not Ready Yet, Try Again Later”? [closed]

人盡茶涼 提交于 2019-11-27 09:33:40
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I'm developing a RESTful API in which http://server/thingyapi/thingyblob/1234 returns the file (aka "blob") associated with thingy #1234 to download. But it may be that the request is made at a time the file does not exist in the server but most definitely will be available

Angular HTTP: Status -1 and CORS

怎甘沉沦 提交于 2019-11-27 07:54:22
问题 In our angular application sometimes we get http status -1 returned to us. The status -1 happens on a popup that is closed, so the user isn't affected by it, just our logs. I attempted to handle it by doing switch (response.status) { case 0: break; case -1: break; case 401: localStorageService.clearAll(); redirectToUrlAfterLogin.url = $location.path(); $location.path('/login'); Which was suggested in AngularJS Issue #12920 We are definitely getting less logs in, but there are still some HTTP

Parsing JSONP Response in Javascript when 4xx or 5xx Http Error Code is Present

一笑奈何 提交于 2019-11-27 07:04:40
问题 I am implementing an application which relies upon communication between a JavaScript client and a server which knows how to respond to the client using JSONP notation. I am attempting to handle the case in my Javascript client where my server returns with an http status code of 4xx or 5xx. Currently what I'm seeing is that the script is not evaluated as the browser believes it to be an error (which it is.) However, I still want to read what my server has to say in the event of this 4xx or

Script to get the HTTP status code of a list of urls?

大兔子大兔子 提交于 2019-11-27 05:55:22
I have a list of URLS that I need to check, to see if they still work or not. I would like to write a bash script that does that for me. I only need the returned HTTP status code, i.e. 200, 404, 500 and so forth. Nothing more. EDIT Note that there is an issue if the page says "404 not found" but returns a 200 OK message. It's a misconfigured web server, but you may have to consider this case. For more on this, see Check if a URL goes to a page containing the text "404" Curl has a specific option, --write-out , for this: $ curl -o /dev/null --silent --head --write-out '%{http_code}\n' <url> 200

How to specify HTTP error code?

时间秒杀一切 提交于 2019-11-27 05:17:43
问题 I have tried: app.get('/', function(req, res, next) { var e = new Error('error message'); e.status = 400; next(e); }); and: app.get('/', function(req, res, next) { res.statusCode = 400; var e = new Error('error message'); next(e); }); but always an error code of 500 is announced. 回答1: Per the Express (Version 4+) docs, you can use: res.status(400); res.send('None shall pass'); http://expressjs.com/4x/api.html#res.status <=3.8 res.statusCode = 401; res.send('None shall pass'); 回答2: A simple

What are proper status codes for CORS preflight requests?

ε祈祈猫儿з 提交于 2019-11-27 04:46:28
What status code should a well-written HTTP server return when it gets a CORS preflight ( OPTIONS ) request? 200 , 204 or something else? Should the status code be different in case origin is allowed (and corresponding headers will be set) or not allowed (and CORS headers will not be set or will not match the origin)? The gist of it is, just use 200 . A little more generally: You should just send back the same status code for the CORS preflight OPTIONS request that you’d send back for any other OPTIONS request. The relevant specs don’t require or recommend anything more than that. As far the

HTTP status code for unaccepted Content-Type in request

半世苍凉 提交于 2019-11-27 03:42:53
问题 For certain resources, my RESTful server only accepts PUT and POST requests with JSON objects as the content body, thus requiring a Content-Type of application/json instead of application/x-www-form-urlencoded or multipart/form-data or anything else. Malformed JSON (or lack thereof) returns a 400 with the error message taken directly from the exception raised by the JSON parser, for debugging purposes. Which HTTP error code means that the client sent a request with an unacceptable Content

How to get HTTP response code for a URL in Java?

半腔热情 提交于 2019-11-27 02:59:43
Please tell me the steps or code to get the response code of a particlular URL. Rob Hruska HttpURLConnection : URL url = new URL("http://example.com"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); int code = connection.getResponseCode(); This is by no means a robust example; you'll need to handle IOException s and whatnot. But it should get you started. If you need something with more capability, check out HttpClient . URL url = new URL("http://www.google.com/humans.txt"); HttpURLConnection http =

Python Request Post with param data

感情迁移 提交于 2019-11-27 02:41:39
This is the raw request for an API call: POST http://192.168.3.45:8080/api/v2/event/log?sessionKey=b299d17b896417a7b18f46544d40adb734240cc2&format=json HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: application/json Content-Length: 86 Host: 192.168.3.45:8080 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5) {"eventType":"AAS_PORTAL_START","data":{"uid":"hfe3hf45huf33545","aid":"1","vid":"1"}}""" This request returns a success (2xx) response. Now I am trying to post this request using requests : >>> import requests >>> headers = {'content-type' : 'application/json'} >>