# Problems with accessing the Get Document service with Java

**URL:** <http://forum.companieshouse.gov.uk/t/problems-with-accessing-the-get-document-service-with-java/400>\
**Category:** API Issues\
**Created:** [January 5, 2016, 12:01pm UTC](http://forum.companieshouse.gov.uk/t/problems-with-accessing-the-get-document-service-with-java/400 "2016-01-05T12:01:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](http://forum.companieshouse.gov.uk/u/richard)\
**Post date:** [January 5, 2016, 12:01pm UTC](http://forum.companieshouse.gov.uk/t/problems-with-accessing-the-get-document-service-with-java/400/1 "2016-01-05T12:01:38Z")

</div>

I am having trouble accessing the Get Document service using Java.

Even on using the Try it Out! option on the website it just sits there and does nothing.

I am accessing the Meta Data part of the service using Java without issue, so it isn’t a problem with authentication, and have accessed Get Document using cURL, getting a 302 response with a valid location included. Using verbose on cURL shows that my request parameters are the same (“GET /document/[ID]/content HTTP/1.1”, “Host: [document-api.companieshouse.gov.uk](http://document-api.companieshouse.gov.uk)”, “Accept: application/pdf”, “Authorization: [same between cURL and Java]”), the only differences are “User-Agent: curl/7.45.0” vs “User-Agent: Java/1.6.0\_10” (although I have passed curl/7.45.0 in with Java to no avail) and passing “Connection: keep-alive” in using Java (I have set this to null, but it made no difference).

I am constantly getting 401 errors when I run using java, but using cURL for the same service and using Java for getting Document Meta Data are returning fine. Does anyone know what the problem could be?

---

<div class="post-metadata">

**Author:** ![mfairhurst](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@mfairhurst](http://forum.companieshouse.gov.uk/u/mfairhurst)\
**Post date:** [January 5, 2016, 1:05pm UTC](http://forum.companieshouse.gov.uk/t/problems-with-accessing-the-get-document-service-with-java/400/2 "2016-01-05T13:05:03Z")

</div>

@richard

This could be related to the HTTP client library automatically following the redirect in the metadata request and sending the the original authorisation header? The following post provides some further explanation.

> [@Document Images](http://forum.aws.chdev.org/t/document-images/26/17):
>
> This happens when a HTTP client library automatically follows the redirect and sends the original Authorization header with the redirected request. The solution is to prevent the HTTP client from following redirects, retrieve the Location header from the response, then create a new request to that URL without the Authorization header. For example, in .Net you can do something like this: string docID = "..."; string apiKey = "..."; string url = "https://document-api.companieshouse.gov.uk/docum…

Let me know if this helps.

Thanks,

Mark.
