Looking back - and this may no longer be the case or not apply to your code - someone did report getting a 404 from a search endpoint when they had provided an incorrectly formatted API key (e.g. they were missing the final ':'):
Caveat - I'm not a java coder but if this is the case then the line:
...will need tweaking.
Oracle's java documentation for URLConnection combined with CH's explanation of http basic authorization suggests that the second parameter would need to evaluate to something like "
Basic YOUR_API_KEY:" - don't know if that's the case here?
Your query seems OK. Running this (curl) brings back search results:
curl -uYOUR_API_KEY_HERE: "https://api.companieshouse.gov.uk/search/companies?q=Apple"
"address_snippet": "85 Great Portland Street, London, England, W1W 7LT",
I found it helpful to work things through like this e.g. checking raw http data in and out of the API. Curl is handy as you can create very simple one-line checks (free from other code complications) and examine traffic (e.g. the -I flag to show headers etc.) There are a multitude of other such tools appropriate to different environments though.