http-status-codes

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

六月ゝ 毕业季﹏ 提交于 2019-11-26 11:47:07
问题 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" 回答1: Curl has a

400 vs 422 response to POST of data

独自空忆成欢 提交于 2019-11-26 11:31:15
I'm trying to figure out what the correct status code to return on different scenarios with a "REST-like" API that I'm working on. Let's say I have a end point that allows POST'ing purchases in JSON format. It looks like this: { "account_number": 45645511, "upc": "00490000486", "price": 1.00, "tax": 0.08 } What should I return if the client sends me "sales_tax" (instead of the expected "tax"). Currently, I'm returning a 400. But, I've started questioning myself on this. Should I really be returning a 422? I mean, it's JSON (which is supported) and it's valid JSON, it's just doesn't contain all

JAX-RS — How to return JSON and HTTP status code together?

▼魔方 西西 提交于 2019-11-26 11:26:36
I'm writing a REST web app (NetBeans 6.9, JAX-RS, TopLink Essentials) and trying to return JSON and HTTP status code. I have code ready and working that returns JSON when the HTTP GET method is called from the client. Essentially: @Path("get/id") @GET @Produces("application/json") public M_機械 getMachineToUpdate(@PathParam("id") String id) { // some code to return JSON ... return myJson; } But I also want to return an HTTP status code (500, 200, 204, etc.) along with the JSON data. I tried to use HttpServletResponse : response.sendError("error message", 500); But this made the browser think it

What are proper status codes for CORS preflight requests?

社会主义新天地 提交于 2019-11-26 11:21:18
问题 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)? 回答1: 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

How do I resolve a HTTP 414 “Request URI too long” error?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 11:16:54
I have developed a PHP web app. I am giving an option to the user to update multiple issues on one go. In doing so, sometimes the user is encountering this error. Is there any way to increase the lenght of URL in apache? John Feminella Under Apache, the limit is a configurable value, LimitRequestLine . Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf . If not, add a new line ( LimitRequestLine 10000 ) under AccessFileName .htaccess . However, note that if you're actually running into this limit

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

♀尐吖头ヾ 提交于 2019-11-26 10:19:09
问题 Please tell me the steps or code to get the response code of a particlular URL. 回答1: 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

How to send a status code in PHP, without maintaining an array of status names?

人走茶凉 提交于 2019-11-26 09:39:12
问题 All I want to do, is send a 404 status code from PHP - but in a generic fashion. Both Router::statusCode(404) and Router::statusCode(403) should work, as well as any other valid HTTP status code. I do know, that you can specify a status code as third parameter to header. Sadly this only works if you specify a string . Thus calling header(\'\', false, 404) does not work. Furthermore I know, that one can send a status code via a header call with a status line: header(\'HTTP/1.1 404 Not Found\')

Http Status Code in Android Volley when error.networkResponse is null

旧时模样 提交于 2019-11-26 09:19:53
问题 I am using Google Volley on the Android platform. I am having a problem in which the error parameter in onErrorResponse is returning a null networkResponse For the RESTful API I am using, I need to determine the Http Status Code which is often arriving as 401 (SC_UNAUTHORIZED) or 500 (SC_INTERNAL_SERVER_ERROR), and I can occasionally check via: final int httpStatusCode = error.networkResponse.statusCode; if(networkResponse == HttpStatus.SC_UNAUTHORIZED) { // Http status code 401: Unauthorized

Python Request Post with param data

喜夏-厌秋 提交于 2019-11-26 09:15:05
问题 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

What HTTP status response code should I use if the request is missing a required parameter?

一世执手 提交于 2019-11-26 09:05:43
问题 I am thinking 412 (Precondition Failed) but there may be a better standard? 回答1: Status 422 seems most appropiate based on the spec. The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error