I am writing a simple REST client in Java that sends requests to a server and retrieve some data. The server uses a token for authorization which has to be included in header (according to documentation).
The problem is I am not sure how to rewrite it correctly correctly. I have a curl
command that works well:
curl --include --header "authorization:a7b857f6.....rest of my token" --header "Content-Type: application/json" https://serverUrl/v1/search?q=someQuery
This request returns the correct answer (some results for a given query in this case).
I tried to rewrite this in Java but I am getting "404 - resource not found although" the query is the same.
public void getResultsByQuery() {
Client client = ClientBuilder.newClient();
Response response = client
.target("https://serverUrl")
.path("/v1/search?q=someQuery")
.request("application/json")
.header("Content-Type", "application/json")
.header("authorization", "a7b857f6-........rest of my token")
.get();
System.out.println("status: " + response.getStatus());
System.out.println("headers: " + response.getHeaders());
System.out.println("body:" + response.readEntity(String.class));
}
Can you give me a hint if I missed something? It will be probably some dumb mistake but I spent several hours trying to make it work and I am clueless.