httpresponse

return text/html content-type when using flask-restful

筅森魡賤 提交于 2019-12-05 12:21:55
In a specific case I'd like to respond with a text/html content-type for an error as follows: class MyResource(Resource): def get(self): if some_condition: return 'bad argument', 400 The code above returns an application/json content-type: '"bad argument"' instead of a text/html content-type: 'bad argument' How can I force flask-restful to respond with text/html content-type? You'll have to use flask.make_response() to return a 'pre-baked' response object: return flask.make_response('bad argument', 400) Flask-Restful will pass full-on Response objects unaltered, rather than try and convert

How to display a progress status/spinner when outputting file via Response.ContentType, Response.End?

£可爱£侵袭症+ 提交于 2019-12-05 12:00:03
I have a webform with a Download LinkButton , on the button's click event I'm fetching data and then generating an .XLSX file for download. During the generation of the file, Response.Clear() is called, Response.ContentType is set and eventually Response.End() is called. I need to display a spinner .gif during that operation. Once the file has been generated and the file "Open/Save" dialog pops up, the spinner should not display . Unfortunately, since I'm changing the content type and calling Response.End there is no response returned back to the page to work with. Can anyone please provide a

PHP: “file_get_contents()” returning NULL from content-verified URL

白昼怎懂夜的黑 提交于 2019-12-05 11:43:09
I'm betting that it'll end up being something simple ... but I can use a hand in spotting it. Problem: When I try to get the contents of a specific local URL via file_get_contents() , it comes back as an empty string '' (length=0). What I've tried: $url = 'http://localhost/bbq/index.php/company/get/id/2131/return/json'; $results = file_get_contents($url); echo'<pre>Results:<br />',var_export($results),'</pre>'; When directly visiting http://localhost/bbq/index.php/company/get/id/2131/return/json , everything echos beautifully: {"id":"2131","value":"Acme Anvil Corp."} To check myself, I tried

Reread a response body from JavaScript's fetch

大城市里の小女人 提交于 2019-12-05 11:11:21
问题 fetch() returns promise which (if successful) resolves to a Response object. A very common thing to do is immediately call Response.json() to convert the response body to a JSON object. If the response body isn't valid JSON, then the Response.json() promise fails with an error. The message is something along the lines of: Unexpected token X in JSON at position 0 That's not very helpful when trying to diagnose the problem; ideally I'd like to be able to see the content from the server (which

Why does HttpURLConnection.getResponseCode() throws IOException? [duplicate]

空扰寡人 提交于 2019-12-05 09:13:42
This question already has an answer here: HttpURLConnection.getResponseCode() throws IOException when code is known 2 answers I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException ? Am i missing something? From javadoc : It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP). Returns: the HTTP Status-Code, or -1 Throws: IOException - if an error occurred connecting to

How to measure request and response time of server?

空扰寡人 提交于 2019-12-05 08:56:58
I am using asynctask and json parsing for getting response from server,How can i measure request and response time,following is code of my web service,can any one help me with this?............................ public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } // function get json from url // by making HTTP POST or GET method public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try { // check for request method if(method.equals("POST")

Django HttpResponseRedirect vs render_to_response - how to get a login form to behave the way I need it to

风格不统一 提交于 2019-12-05 07:48:18
问题 I've already checked out the following stackoverflow question regarding the difference between HttpResponse, HttpResponseRedirect, and render_to_response, as well as having gone through the official django docs, but I'm really uncertain how best to get the functionality I'm looking to create. Right now I have an index.html with a login function (as seen in the views.py below) where the render_to_response that brings me to portal/index.html . However, as urls.py (see below) dictates, the url

SSL slow. Establishing secure connection taking too long

孤街浪徒 提交于 2019-12-05 07:13:28
I have a dedicated server with 256GB RAM 6 CPUs (12 Threads) on Hetzner, and it is located in Germany. I have CENTOS 7.5 . EA4 . My problem is with SSL. Every day for about 2 hours , we have 40 requests in one second and finishing requests takes about 20 seconds . Non-SSL takes 0.5 or less. Here is an example. From 13:00 to 15:30 (UTC+4) , SSL requests take the most time. The problem is evident when you open this link with SSL and without. I have WHM available. I've noticed ModSecurity and wonder if it might be the problem. I've applied most of the settings provided here , but there is not

Tornado - What is the difference between RequestHandler's get_argument(), get_query_argument() and get_body_argument()?

别来无恙 提交于 2019-12-05 04:18:03
When to use RequestHandler.get_argument() , RequestHandler.get_query_argument() and RequestHandler.get_body_argument() ? What is the use-case for each of them? Also what does the request.body and request.argument do in these cases? Which are to be used in which scenarios? And, is there a request.query or something similar too? Most HTTP requests store extra parameters (say, form values) in one of two places: the URL (in the form of a ?foo=bar&spam=eggs query string ), or in the request body (when using a POST request and either the application/x-www-form-urlencoded or multipart/form-data mime

How to display Image received as byte array in Angular JS

浪尽此生 提交于 2019-12-05 04:13:33
I have a server side application that will return an image. These are the response headers: Content-Disposition: attachment; filename=8822a009-944e-43f4-999b-d297198d302a;1.0_low-res Content-Length: 502343 Content-Type: image/png Date: Mon, 03 Aug 2015 19:13:39 GMT Server: Apache-Coyote/1.1 In angular, I need to display the image. When getting the image, I use the angularJS $http to call the server and put the result in scope, but I never reach the success function of $http . Executing this call from postman returns the image normally. I'm curious to how to get Angular to display the image.