httpresponse

generate csv from mvc web api httpresponse and receive it by angularjs for download

丶灬走出姿态 提交于 2019-12-07 11:45:25
问题 I am trying to generate a CSV file from my web api and receive that file through angularjs. I have an API controller like below: [HttpPost] public HttpResponseMessage GenerateCSV(FieldParameters fieldParams) { var output = new byte[] { }; if (fieldParams!= null) { using (var stream = new MemoryStream()) { this.Serialize(fieldParams, stream); stream.Flush(); output = stream.ToArray(); } } var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(output) }; result

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

谁说我不能喝 提交于 2019-12-07 11:33:50
问题 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? 回答1: You'll have to use flask.make_response() to return a 'pre-baked' response object: return flask.make_response('bad

Spring MV 3.2 Exception Response Mapping

时光怂恿深爱的人放手 提交于 2019-12-07 10:45:15
问题 Spring 3.2.15, MVC-based REST API here ( not Spring Boot, sadly!). I am trying to implement an exception mapper/handler that meets the following criteria: No matter what happens (success or error), the Spring app always returns a response entity of MyAppResponse (see below); and In the event of processing a request successfully, return an HTTP status of 200 (typical); and In the event of processing a request and an exception occurs, I need to control the mapping of the specific exception to a

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

大兔子大兔子 提交于 2019-12-07 08:55:26
问题 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

Is there a limit of the size of response I can read over HTTP

元气小坏坏 提交于 2019-12-07 08:32:18
问题 I have a java program, that calls a url. The response of url is a json/string. I have to write a program that fetches the data from this url, but I was wondering if there's a limit on the max size HTTP can pass back? I was going to write my server side (url) in such a way that it fetches all the data from db, but if there's a limit on the size I can fetch from server, I can do the read in batches also? So, is there a limit on the size of the response I can send over HTTP from server to my

Exception occurs when I try to pass a custom error to client in spring boot application

江枫思渺然 提交于 2019-12-07 08:02:35
问题 java.lang.IllegalStateException: Cannot call sendError() after the response has been committed As above mentioned I am getting an error in the line response .sendError() method. I have searched the internet for 4 days. But I couldn't figure out the problem. What can be the reason for this problem? I have a custom exception class. In the following code, the catch block is successfully caught my custom exception. But when I try to send it to the client side it returns the exception mentioned

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

爷,独闯天下 提交于 2019-12-07 05:19:24
问题 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

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

强颜欢笑 提交于 2019-12-07 04:08:23
问题 This question already has answers here : HttpURLConnection.getResponseCode() throws IOException when code is known (2 answers) Closed 3 years ago . 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? 回答1: From javadoc: It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e

Read raw http message in Nodejs

假如想象 提交于 2019-12-07 02:00:58
问题 I'm sending an http request using the http.request function, and I would like to read the whole http response like text; that is, the raw http protocol text. Is it possible? I've written the below code but it's not working. // Set up the request console.log('Sending request'); var post_req = http.request(post_options, function(res) { res.setEncoding('utf8'); console.log('Response statusCode: ' + res.statusCode); // res.on('data', function (chunk) { // console.log('Response: ' + chunk); // });

SSL slow. Establishing secure connection taking too long

大憨熊 提交于 2019-12-07 01:35:43
问题 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