httpresponse

Symfony run code after response was sent

↘锁芯ラ 提交于 2019-12-09 15:53:16
问题 I took a look at this other question. I am looking for a way to do what the OP of that question wants as well, and that is to continue processing php after sending http response, but in Symfony2. I implemented an event that fires after every kernel termination. So far so good, but what I want is for it to fire after CERTAIN terminations, in specific controller actions, for instance after a form was sent, not every single time at every request. That is because I want to do some heavy tasks at

Setting both error message and body from servlet

瘦欲@ 提交于 2019-12-09 15:36:46
问题 I want to write a servlet that will return an http response like so: HTTP/1.1 500 <short custom message> Content-Length: ... <longer custom message> The reason is that I want a programmatic client to be able to process the response message to take a particular response but I also want to fill in the response body with a longer explanation so that it's easy to hit using a browser. Now, HttpServletResponse has a sendError(int, String) method that allows me to specify the error code and a

how do I get a string from my http response android?

三世轮回 提交于 2019-12-09 14:51:42
问题 I've seen some really ugly looking code from people writing up their own methods of converting an HttpResponse to a string to use later, that looks something like this: httppost.setEntity(new UrlEncodedFormEntity(valuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF8"),8); StringBuilder sb = new StringBuilder(); sb.append(reader

Make Django return response as a “different filename”

风流意气都作罢 提交于 2019-12-09 14:19:57
问题 I have a Django view which returns an HttpResponse with a special MIME type to make the user's browser "download" the file instead of view it in the browser. The problem is that the default filename that the response will be saved as is the URL which the user tried to access. Is there any way to include a default filename in the HttpResponse object or do I have to redirect to a different URL to make this happen? 回答1: There's a relevant example in the docs: from django.http import HttpResponse

When an ASP.NET System.Web.HttpResponse.End() is called, the current thread is aborted?

余生长醉 提交于 2019-12-09 05:08:45
问题 when a System.Web.HttpResponse.End() is called a System.Thread.Abort is being fired, which i'm guessing is (or fires) an exception? I've got some logging and this is being listed in the log file... A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll 12/14/2008 01:09:31:: Error in Path :/authenticate Raw Url :/authenticate Message :Thread was being aborted. Source :mscorlib Stack Trace : at System.Threading.Thread.AbortInternal() at System

HTTPResponse as JSON in Java

≡放荡痞女 提交于 2019-12-08 19:39:39
问题 I was trying to get an JSONObject from a HTTP response. try { GetMethod postMethod = new GetMethod(); postMethod.setURI(new URI(url, true)); postMethod.setRequestHeader("Accept", "application/json"); httpClient.executeMethod(postMethod); String resp=postMethod.getResponseBodyAsString(); org.json.JSONTokener tokener = new org.json.JSONTokener(resp); finalResult = new org.json.JSONArray(tokener); return finalResult; } But I got a runtime warning as Going to buffer response body of large or

How do I get the content length of a Django response object?

岁酱吖の 提交于 2019-12-08 15:42:21
问题 In Django, I try to logging the request and response content length, which exactly the same as what Django server prints to stderr. [05/Apr/2011 22:59:08] "GET /pages/ HTTP/1.1" 200 332161 [05/Apr/2011 22:59:15] "GET /pages/12 HTTP/1.1" 301 0 [05/Apr/2011 22:59:15] "GET /pages/12/ HTTP/1.1" 200 361474 [05/Apr/2011 22:59:16] "GET /pages/12/load/tags/ HTTP/1.1" 200 13899 [05/Apr/2011 22:59:16] "GET /pages/12/load/comments/ HTTP/1.1" 200 82 So, I write a simple middleware as follows, but, the

How to specify a generic type class for Swagger API response

江枫思渺然 提交于 2019-12-08 15:05:29
问题 I have about 40 APIs that have similar base response structure as follows: { "lastAccessed": "2015-30-08:14:21:45T", "createdOn": "2015-30-07:09:04:10T", "lastModified": "2015-30-08:14:21:45T", "isReadOnly": "false", "usersAllowed" : ["Tim", "Matt", "Christine"]; "noOfEntries": 1, "object": [ "ObjectA": { //here object A has its own model } ] } So I have a base response class taking a generic of type T as follows: public class Response<T> { @ApiModelProperty(value="Last time accessed")

How do you set up the correct HTTP Response object for a Range request coming from BITS (Background Intelligent Transfer Service)?

╄→гoц情女王★ 提交于 2019-12-08 09:10:26
问题 I have a requirement to implement a web-service that can issue files to the bits (Background Intelligent Transfer Service). The language is ASP.NET (C#). The problem I am having is with the "range" stuff. My code currently receives the http request (with a valid range is present in the http headers of 0 - 4907), and subsequently dishes out a portion of a byte array in the response object. Here's my server code: _context.Response.Clear(); _context.Response.AddHeader("Content-Range", "bytes " +

using request builder to authenticate user: Not working in spring security

痞子三分冷 提交于 2019-12-08 07:52:54
问题 I need to authenticate a user in a page based on the remember me cookie, inspired by this site: Tutorial for checking spring authentication, I came up with a solution for checking the authentication. Changes made in my application applicationContext-security.xml: <intercept-url pattern='/**AuthenticationChecker.html' access="ROLE_ADMIN"/> ... <form-login login-page="/Login.html" authentication-failure-url="/Login.html" always-use-default-target="true" default-target-url="/Main.html"/> Gwt