Ah. Okay, there are several things wrong here:
- You are sending your API requests to the WEBSITE.
- Your authorisation header is wrong.
First, do not be confused that the URLs look similar for the API and the website. The API will return data encoded as JSON. The Website will of course return HTML, plus, if you scrape the website, you'll no doubt have your IP blocked by our access control infrastructure....
Your problem stems from you not authenticating properly, hence the HTTP status code of "401 Unauthorised" you are getting.
If you search the forum (and I really do urge people to do this, as this has been answered many times before), there are several topics that show you how to correct your error. Most come down to users of the API not providing
HTTP Basic authentication:
Quite a few HTTP clients natively handle Basic authentication, so for them it is a simple matter of setting the username and the password (which in our case is blank) on the client instance before making the call. For other clients, you have to set the Basic authentication header yourself.
We have posted a simple Perl example to demonstrate the Basic authentication mechanism if you have to set the header yourself. You should be able to translate the two important lines of Perl into two lines of Java to do the same. This example also shows how a
curl request works, as it natively handles Basic authentication, demonstrating what headers are being sent, and what they contain:
Finally, a quick web search for
URLConnection BASIC authentication returns the following first hit, which actually provides the two lines of Java I mentioned above:
That and the Perl example should get you up and running. Perhaps you could come back and post your corrected code snippet here, when you get it working, to close this topic off?
Hope that helps. Good luck!