<?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>Sun, 29 Apr 2012 15:11:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</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[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><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-publisher-222"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></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: And finally the code to execute the request:]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop --><!-- End Shareaholic LikeButtonSetTop --><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; title: ; notranslate">
&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; title: ; notranslate">
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-publisher-204"></div><!-- Start Shareaholic LikeButtonSetBottom --><!-- End Shareaholic LikeButtonSetBottom -->]]></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>

