I want to program a CURL Webservice Client with Java but it doesn't work.
I want make a client of this
curl "https://api.esios.ree.es/archives" -X GET \
-H "Accept: application/json; application/vnd.esios-api-v1+json" \
-H "Content-Type: application/json" \
-H "Host: api.esios.ree.es" \
-H "Authorization: Token token=\"96c56fcd69dd5c29f569ab3ea9298b37151a1ee488a1830d353babad3ec90fd7\"" \
-H "Cookie: "
I make a little program using com.sun.jersey.api.client.Client and ClientResponse but fail. The example is that:
Client client = Client.create();
WebResource webResource =client.resource("https://api.esios.ree.es/archive");
MultivaluedMap queryParams = new MultivaluedMapImpl();
queryParams.add("Accept", "application/json; application/vnd.esios-api-v1+json");
queryParams.add("Content-Type", "application/json");
queryParams.add("Host", "api.esios.ree.es");
queryParams.add("Authorization", "Token token=\"96c56fcd69dd5c29f569ab3ea9298b37151a1ee488a1830d353babad3ec90fd7\"");
queryParams.add("Cookie", " ");
ClientResponse response = webResource.queryParams(queryParams).accept("application/json").get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
The code response Failed : HTTP error code : 401. Thanks a lot for try to help me.
https://api.esios.ree.es/archivesin first code sample andhttps://api.esios.ree.es/archivein the second