<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>indiWiz.com &#187; http</title>
	<atom:link href="http://indiwiz.com/tag/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://indiwiz.com</link>
	<description>Subhash&#039;s Tech Log</description>
	<lastBuildDate>Wed, 03 Mar 2010 13:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Forcing HTTP Download</title>
		<link>http://indiwiz.com/2009/03/11/forcing-http-download/</link>
		<comments>http://indiwiz.com/2009/03/11/forcing-http-download/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 06:06:14 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Software Dev]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=222</guid>
		<description><![CDATA[To force HTTP download of a dynamically generated content, I usually set the HTTP header Content-Type to application/octet-stream. This forces the browser to display the Save dialog box. But this has the limitation of sending the wrong content-type even when we know the correct one. Recently I discovered another HTTP header which solves this problem. [...]]]></description>
			<content:encoded><![CDATA[<p>To force HTTP download of a dynamically generated content, I usually set the HTTP header <tt>Content-Type</tt> to <i>application/octet-stream</i>. This forces the browser to display the Save dialog box. But this has the limitation of sending the wrong content-type even when we know the correct one. Recently I discovered another HTTP header which solves this problem. This is the <tt>Content-Disposition</tt> header. This can take following two vales:</p>
<ol>
<li><b>inline</b>: This will render the content inline in the browser.</li>
<li><b>attachment</b>: This will force the browser to display the Save dialog.</li>
</ol>
<p>When generating dynamic content, it is also recommended to specify proper filename. This file name can also be specified as a parameter to <tt>Content-Disposition</tt> header. An example:</p>
<pre>
Content-Disposition: attachment;filename=document.pdf
</pre>
<p>&nbsp;<br /><tt>Content-Disposition</tt> is covered in <a href="http://www.ietf.org/rfc/rfc2183.txt">RFC 2183</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2009/03/11/forcing-http-download/&amp;title=Forcing+HTTP+Download" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2009/03/11/forcing-http-download/&amp;title=Forcing+HTTP+Download" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2009/03/11/forcing-http-download/&amp;title=Forcing+HTTP+Download&amp;desc=To%20force%20HTTP%20download%20of%20a%20dynamically%20generated%20content%2C%20I%20usually%20set%20the%20HTTP%20header%20Content-Type%20to%20application%2Foctet-stream.%20This%20forces%20the%20browser%20to%20display%20the%20Save%20dialog%20box.%20But%20this%20has%20the%20limitation%20of%20sending%20the%20wrong%20content-type%20even%20when%20we%20know%20the%20correct%20one.%20Recently%20I%20disco" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2009/03/11/forcing-http-download/&amp;t=Forcing+HTTP+Download" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2009/03/11/forcing-http-download/&amp;title=Forcing+HTTP+Download&amp;summary=To%20force%20HTTP%20download%20of%20a%20dynamically%20generated%20content%2C%20I%20usually%20set%20the%20HTTP%20header%20Content-Type%20to%20application%2Foctet-stream.%20This%20forces%20the%20browser%20to%20display%20the%20Save%20dialog%20box.%20But%20this%20has%20the%20limitation%20of%20sending%20the%20wrong%20content-type%20even%20when%20we%20know%20the%20correct%20one.%20Recently%20I%20disco&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2009/03/11/forcing-http-download/&amp;title=Forcing+HTTP+Download" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2009/03/11/forcing-http-download/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multi-part content upload in Apache Http Components / Http Client</title>
		<link>http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/</link>
		<comments>http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 15:59:57 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[httpclient]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=204</guid>
		<description><![CDATA[Apache Http Components project hosts an excellent library for making HTTP client requests. This is a simple example for making multipart/form-data request. Dependencies to be added to you Maven project: &#60;dependency&#62; &#60;groupId&#62;org.apache.httpcomponents&#60;/groupId&#62; &#60;artifactId&#62;httpmime&#60;/artifactId&#62; &#60;version&#62;4.0-beta2&#60;/version&#62; &#60;/dependency&#62; &#60;dependency&#62; &#60;groupId&#62;org.apache.httpcomponents&#60;/groupId&#62; &#60;artifactId&#62;httpclient&#60;/artifactId&#62; &#60;version&#62;4.0-beta2&#60;/version&#62; &#60;/dependency&#62; And finally the code to execute the request: import java.io.File; import java.io.IOException; import java.net.URL; import [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hc.apache.org/">Apache Http Components</a> project hosts an excellent library for making HTTP client requests. This is a simple example for making <tt>multipart/form-data</tt> request.</p>
<p>Dependencies to be added to you Maven project:</p>
<pre class="brush: xml;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
    &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
    &lt;version&gt;4.0-beta2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
    &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
    &lt;version&gt;4.0-beta2&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<p>And finally the code to execute the request:</p>
<pre class="brush: java;">
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;

...

// The input:
File f = ...;
String title = ...;
String desc = ...;

// The execution:
DefaultHttpClient httpclient = new DefaultHttpClient();

HttpPost method = new HttpPost(&quot;http://host:port/path&quot;);
MultipartEntity entity = new MultipartEntity();
entity.addPart(&quot;title&quot;, new StringBody(title, Charset.forName(&quot;UTF-8&quot;)));
entity.addPart(&quot;desc&quot;, new StringBody(desc, Charset.forName(&quot;UTF-8&quot;)));
FileBody fileBody = new FileBody(f);
entity.addPart(&quot;file&quot;, fileBody);
method.setEntity(entity);

HttpResponse response = httpclient.execute(method);
System.out.println(response.getStatusLine());
</pre>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/&amp;title=Multi-part+content+upload+in+Apache+Http+Components+%2F+Http+Client" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/&amp;title=Multi-part+content+upload+in+Apache+Http+Components+%2F+Http+Client" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/&amp;title=Multi-part+content+upload+in+Apache+Http+Components+%2F+Http+Client&amp;desc=Apache%20Http%20Components%20project%20hosts%20an%20excellent%20library%20for%20making%20HTTP%20client%20requests.%20This%20is%20a%20simple%20example%20for%20making%20multipart%2Fform-data%20request.%0A%0ADependencies%20to%20be%20added%20to%20you%20Maven%20project%3A%0A%0A%5Bsourcecode%20language%3D%22xml%22%5D%0A%0A%20%20%20%20org.apache.httpcomponents%0A%20%20%20%20httpmime%0A%20%20%20%204.0-beta2%0A%0A%0A%20%20%20%20org" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/&amp;t=Multi-part+content+upload+in+Apache+Http+Components+%2F+Http+Client" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/&amp;title=Multi-part+content+upload+in+Apache+Http+Components+%2F+Http+Client&amp;summary=Apache%20Http%20Components%20project%20hosts%20an%20excellent%20library%20for%20making%20HTTP%20client%20requests.%20This%20is%20a%20simple%20example%20for%20making%20multipart%2Fform-data%20request.%0A%0ADependencies%20to%20be%20added%20to%20you%20Maven%20project%3A%0A%0A%5Bsourcecode%20language%3D%22xml%22%5D%0A%0A%20%20%20%20org.apache.httpcomponents%0A%20%20%20%20httpmime%0A%20%20%20%204.0-beta2%0A%0A%0A%20%20%20%20org&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/&amp;title=Multi-part+content+upload+in+Apache+Http+Components+%2F+Http+Client" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2009/02/11/multi-part-content-upload-in-apache-http-components-http-client/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
