API's HTTP response yields the entire HTML page instead of the response's body
<p>I am currently writing a Java program that uses <a href="http://freecite.library.brown.edu/welcome" rel="nofollow">FreeCite</a> API (a citation extraction service) - the API guide is defined <a href="http://freecite.library.brown.edu/welcome/api_instructions" rel="nofollow">here</a>
(there is an example in Ruby). I've been trying the API using Java (Apache HttpClient) for days, but it doesn't work as expected.</p>

<h1>Here is the example in Ruby</h1>

<p><strong>Code:</strong></p>

<pre><code>require 'net/http'

Net::HTTP.start('localhost', 3000) do |http|
  response = http.post('/citations/create',
    'citation=A. Bookstein and S. T. Klein,  \
    Detecting content-bearing words by serial clustering,  \
Proceedings of the Nineteenth Annual International ACM SIGIR Conference \
on Research and Development in Information Retrieval,   \
pp. 319327,   1995.',
'Accept' =&gt; 'text/xml')

  puts "Code: #{response.code}"
  puts "Message: #{response.message}"
  puts "Body:\n #{response.body}"
end
</code></pre>

<p>n.b.: <code>localhost</code> refers to FreeCite. The expected response code is 201, and the response is XML.</p>

<p><strong>Result:</strong></p>

<pre><code>&lt;citations&gt;
  &lt;citation valid=true&gt;
  &lt;authors&gt;
    &lt;author&gt;I S Udvarhelyi&lt;/author&gt;
    &lt;author&gt;C A Gatsonis&lt;/author&gt;
    &lt;author&gt;A M Epstein&lt;/author&gt;
    &lt;author&gt;C L Pashos&lt;/author&gt;
    &lt;author&gt;J P Newhouse&lt;/author&gt;
    &lt;author&gt;B J McNeil&lt;/author&gt;
  &lt;/authors&gt;
  &lt;title&gt;Acute Myocardial Infarction in the Medicare population: process of care and clinical outcomes&lt;/title&gt;
  &lt;journal&gt;Journal of the American Medical Association&lt;/ journal&gt;
  &lt;pages&gt;18--2530&lt;/pages&gt;
  &lt;year&gt;1992&lt;/year&gt;
  &lt;raw_string&gt;Udvarhelyi, I.S., Gatsonis, C.A., Epstein, A.M., Pashos, C.L., Newhouse, J.P. and McNeil, B.J. Acute Myocardial Infarction in the Medicare population: process of care and clinical outcomes. Journal of the American Medical Association, 1992; 18:2530-2536.&lt;/raw_string&gt;
  &lt;ctx:context-objects xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='info:ofi/fmt:xml:xsd:ctx http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx' xmlns:ctx='info:ofi/fmt:xml:xsd:ctx'&gt;
    &lt;ctx:context-object timestamp='2008-07-11T00:57:33-04:00'
    encoding='info:ofi/enc:UTF-8' version='Z39.88-2004' identifier=''&gt;
      &lt;ctx:referent&gt;
        &lt;ctx:metadata-by-val&gt;
          &lt;ctx:format&gt;info:ofi/fmt:xml:xsd:journal&lt;/ctx:format&gt;
          &lt;ctx:metadata&gt;
            &lt;journal xmlns:rft='info:ofi/fmt:xml:xsd:journal' xsi:schemaLocation='info:ofi/fmt:xml:xsd:journal http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:journal'&gt;
              &lt;rft:atitle&gt;Acute Myocardial Infarction in the Medicare population: process of care and clinical outcomes&lt;/rft:atitle&gt;
              &lt;rft:spage&gt;18&lt;/rft:spage&gt;
              &lt;rft:date&gt;1992&lt;/rft:date&gt;
              &lt;rft:stitle&gt;Journal of the American Medical Association&lt;/rft:stitle&gt;
              &lt;rft:genre&gt;article&lt;/rft:genre&gt;
              &lt;rft:epage&gt;2530&lt;/rft:epage&gt;
              &lt;rft:au&gt;I S Udvarhelyi&lt;/rft:au&gt;
              &lt;rft:au&gt;C A Gatsonis&lt;/rft:au&gt;
              &lt;rft:au&gt;A M Epstein&lt;/rft:au&gt;
              &lt;rft:au&gt;C L Pashos&lt;/rft:au&gt;
              &lt;rft:au&gt;J P Newhouse&lt;/rft:au&gt;
              &lt;rft:au&gt;B J McNeil&lt;/rft:au&gt;
            &lt;/journal&gt;
          &lt;/ctx:metadata&gt;
        &lt;/ctx:metadata-by-val&gt;
      &lt;/ctx:referent&gt;
    &lt;/ctx:context-object&gt;
  &lt;/ctx:context-objects&gt;
  &lt;/citation&gt;
&lt;/citations&gt;
</code></pre>

<h2>Here's my project:</h2>

<p><strong>Code:</strong></p>

<pre><code>import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;

public class HttpClientTest {

    public static void main(String[] args) throws UnsupportedEncodingException {
        HttpClient httpclient = HttpClients.createDefault();
        HttpPost httppost = new HttpPost("http://freecite.library.brown.edu/citations/create");

        // Request parameters and other properties.
        List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
        params.add(new BasicNameValuePair("citation", "A. Bookstein and S. T. Klein, Detecting content-bearing words by serial clustering, "
                + "Proceedings of the Nineteenth Annual International ACM SIGIR Conference on Research and Development in Information Retrieval, pp. 319327, 1995."));
        httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

        //Execute and get the response.
        HttpResponse response = null;
        try {
            response = httpclient.execute(httppost);
            response.setHeader("Content-Type", "text/xml");

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpEntity entity = response.getEntity();
        System.out.println(response.getStatusLine());

        if (entity != null) {
            InputStream instream = null;
            try {
                instream = entity.getContent();
                // NB: does not close inputStream, you can use IOUtils.closeQuietly for that
                String theString = IOUtils.toString(instream, "UTF-8"); 
                IOUtils.closeQuietly(instream);
                System.out.println(theString);
            } catch (UnsupportedOperationException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                // do something useful
            } finally {
                try {
                    instream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
</code></pre>

<p><strong>Result:</strong></p>

<p>I got the <em>entire HTML page, instead of the XML</em>; and <em>response code 200 instead of 201</em>.</p>

<pre><code>HTTP/1.1 200 

&lt;script src="/javascripts/prototype.js?1218559878" type="text/javascript"&gt;&lt;/script&gt;
&lt;link href="/stylesheets/citation.css?1218559878" media="screen" rel="stylesheet" type="text/css" /&gt;
&lt;table&gt;

  &lt;tr&gt;
  &lt;td&gt;
  &lt;span class="citation"&gt; &lt;span class="authors"&gt; &lt;span class="author"&gt; A Bookstein&lt;/span&gt; &lt;span class="author"&gt; S T Klein&lt;/span&gt; &lt;/span&gt; &lt;span class="title"&gt; Detecting content-bearing words by serial clustering&lt;/span&gt; &lt;span class="booktitle"&gt; Proceedings of the Nineteenth Annual International ACM SIGIR Conference on Research and Development in Information Retrieval&lt;/span&gt; &lt;span class="pages"&gt; 319327&lt;/span&gt; &lt;span class="year"&gt; 1995&lt;/span&gt; &lt;br&gt; &lt;span class="raw_string"&gt; A. Bookstein and S. T. Klein, Detecting content-bearing words by serial clustering, Proceedings of the Nineteenth Annual International ACM SIGIR Conference on Research and Development in Information Retrieval, pp. 319327, 1995.&lt;/span&gt; &lt;/span&gt; 
  &lt;br&gt;
  &lt;code&gt; &amp;lt;ctx:context-objects xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='info:ofi/fmt:xml:xsd:ctx http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx' xmlns:ctx='info:ofi/fmt:xml:xsd:ctx'&amp;gt;&amp;lt;ctx:context-object timestamp='2016-10-29T02:43:38-04:00' encoding='info:ofi/enc:UTF-8' version='Z39.88-2004' identifier=''&amp;gt;&amp;lt;ctx:referent&amp;gt;&amp;lt;ctx:metadata-by-val&amp;gt;&amp;lt;ctx:format&amp;gt;info:ofi/fmt:xml:xsd:book&amp;lt;/ctx:format&amp;gt;&amp;lt;ctx:metadata&amp;gt;&amp;lt;book xmlns:rft='info:ofi/fmt:xml:xsd:book' xsi:schemaLocation='info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book'&amp;gt;&amp;lt;rft:atitle&amp;gt;Detecting content-bearing words by serial clustering&amp;lt;/rft:atitle&amp;gt;&amp;lt;rft:date&amp;gt;1995&amp;lt;/rft:date&amp;gt;&amp;lt;rft:btitle&amp;gt;Proceedings of the Nineteenth Annual International ACM SIGIR Conference on Research and Development in Information Retrieval&amp;lt;/rft:btitle&amp;gt;&amp;lt;rft:genre&amp;gt;proceeding&amp;lt;/rft:genre&amp;gt;&amp;lt;rft:pages&amp;gt;319327&amp;lt;/rft:pages&amp;gt;&amp;lt;rft:au&amp;gt;A Bookstein&amp;lt;/rft:au&amp;gt;&amp;lt;rft:au&amp;gt;S T Klein&amp;lt;/rft:au&amp;gt;&amp;lt;/book&amp;gt;&amp;lt;/ctx:metadata&amp;gt;&amp;lt;/ctx:metadata-by-val&amp;gt;&amp;lt;/ctx:referent&amp;gt;&amp;lt;/ctx:context-object&amp;gt;&amp;lt;/ctx:context-objects&amp;gt; &lt;/code&gt;
  &lt;/td&gt;

  &lt;td bgcolor="FF9999" class='choose_option'&gt;
    &lt;input id="unusable"
      name="citation_rating_13655375"
      type="radio"
      value="unusable"
      onclick="new Ajax.Request('/citations/set_rating/13655375', {parameters:{rating: this.value} }); return true;"
       /&gt;
    &lt;label for='unusable'&gt;unusable&lt;/label&gt;
  &lt;/td&gt;

  &lt;td bgcolor="FFFFCC" class='choose_option'&gt;
    &lt;input id="usable"
      name="citation_rating_13655375"
      type="radio"
      value="usable"
      onclick="new Ajax.Request('/citations/set_rating/13655375', {parameters:{rating: this.value} }); return true;"
       /&gt;
    &lt;label for='usable'&gt;good enough&lt;/label&gt;
  &lt;/td&gt;

  &lt;td bgcolor="CCFFCC" class='choose_option'&gt;
    &lt;input id="perfect"
      name="citation_rating_13655375"
      type="radio"
      value="perfect"
    onclick="new Ajax.Request('/citations/set_rating/13655375', {parameters:{rating: this.value} }); return true;"
       /&gt;
    &lt;label for='perfect'&gt;perfect&lt;/label&gt;
  &lt;/td&gt;

  &lt;/tr&gt;

&lt;/table&gt;

&lt;br&gt;
Key:
&lt;span title="author" class="author"&gt;Authors&lt;/span&gt;
&lt;span title="title" class="title"&gt;Title&lt;/span&gt;
&lt;span title="journal" class="journal"&gt;Journal&lt;/span&gt;
&lt;span title="booktitle" class="booktitle"&gt;Booktitle&lt;/span&gt;
&lt;span title="editor" class="editor"&gt;Editor&lt;/span&gt;
&lt;span title="volume" class="volume"&gt;Volume&lt;/span&gt;
&lt;span title="publisher" class="publisher"&gt;Publisher&lt;/span&gt;
&lt;span title="institution" class="institution"&gt;Institution&lt;/span&gt;
&lt;span title="location" class="location"&gt;Location&lt;/span&gt;
&lt;span title="number" class="number"&gt;Number&lt;/span&gt;
&lt;span title="pages" class="pages"&gt;Pages&lt;/span&gt;
&lt;span title="year" class="year"&gt;Year&lt;/span&gt;
&lt;span title="tech" class="tech"&gt;Tech&lt;/span&gt;
&lt;span title="note" class="note"&gt;Note&lt;/span&gt;
&lt;br&gt;
&lt;span class="raw_string"&gt;Original citation string&lt;/span&gt;
&lt;br&gt;
&lt;code&gt;ContextObject&lt;/code&gt;
&lt;br&gt;
&lt;a href="/welcome"&gt;Home&lt;/a&gt;
</code></pre>

<p>n.b.: Inside the <code>&lt;code&gt;</code> tag above, there is this XML data:</p>

<pre><code>&lt;rft:atitle&gt;Detecting content-bearing words by serial clustering&lt;/rft:atitle&gt;
&lt;rft:date&gt;1995&lt;/rft:date&gt;
&lt;rft:btitle&gt;Proceedings of the Nineteenth Annual International ACM SIGIR Conference on Research and Development in Information Retrieval&lt;/rft:btitle&gt;
&lt;rft:genre&gt;proceeding&lt;/rft:genre&gt;
&lt;rft:pages&gt;319327&lt;/rft:pages&gt;
&lt;rft:au&gt;A Bookstein&lt;/rft:au&gt;
&lt;rft:au&gt;S T Klein&lt;/rft:au&gt;
</code></pre>

<p><strong>Question:</strong>
Where is the error and how could I fix this to get an XML response (w/ response code 201)?</p>