XlsxWriter object save as http response to create download in Django

A little update on @alecxe response for Python 3 (io.BytesIO instead of StringIO.StringIO) and Django >= 1.5 (content_type instead of mimetype), with the fully in-memory file assembly that has since been implemented by @jmcnamara ({‘in_memory’: True}) ! Here is the full example : import io from django.http.response import HttpResponse from xlsxwriter.workbook import Workbook def your_view(request): … Read more

Disable all default HTTP error response content in Tomcat

If you do not want tomcat to show an error page, then do not use sendError(…). Instead use setStatus(…). e.g. if you want to give a 405 response, then you do response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); response.getWriter().println(“The method ” + request.getMethod() + ” is not supported by this service.”); Also remember not to throw any Exceptions from your servlet. … Read more

How to get read data from response header in jquery/javascript [duplicate]

Both XMLHttpRequest and jqXHR (which is the object jQuery wraps around AJAX requests) have a getResponseHeader() method, so in the always() handler (jQuery) or readyState handler (XMLHttpRequest), do this.getResponseHeader(‘Location’). Bear in mind that if your server also sends a redirect status code (301/ 302) that redirect will be automatically followed, and there’s no way to … Read more

HonyComb and DefaultHttpClient

There are new policies that allow application and operating system developers to set performance expectations for code executing on certain threads. You’ve attempted to invoke blocking network api’s on the ui thread of your application. Google has put in place a system that lets you know this is a bad idea and you can resolve … Read more

Get Content-Disposition parameters

If you are working with .NET 4.5 or later, consider using the System.Net.Mime.ContentDisposition class: string cpString = wc.ResponseHeaders[“Content-Disposition”]; ContentDisposition contentDisposition = new ContentDisposition(cpString); string filename = contentDisposition.FileName; StringDictionary parameters = contentDisposition.Parameters; // You have got parameters now Edit: otherwise, you need to parse Content-Disposition header according to it’s specification. Here is a simple class that … Read more

HttpCookieCollection.Add vs HttpCookieCollection.Set – Does the Request.Cookies collection get copied to the Response.Cookies collection?

There is a difference: Response.Cookies.Add() will allow duplicate cookies to be set http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.add.aspx Response.Cookies.Set() will make sure the cookie is unique by first checking to ensure the cookie doesn’t exist http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.set.aspx Duplicate cookies typically requires extra handling to determine which is the most recent. I’m not sure of a case when you would want duplicate … Read more

How to print out returned message from HttpResponse?

Use ResponseHandler. One line of code. See here and here for sample Android projects using it. public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(“http://www.yoursite.com/user”); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair(“id”, “12345”)); nameValuePairs.add(new BasicNameValuePair(“stringdata”, “AndDev … Read more