我想用Java編程CURL Webservice客戶端,但它不起作用。CURL和JAVA錯誤
我想使這個
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: "
客戶端讓我用com.sun.jersey.api.client.Client和ClientResponse一個小程序,但失敗。 的例子是:
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());
}
代碼響應失敗:HTTP錯誤代碼:401。非常感謝試圖幫助我。
看起來你發送那些爲queryParams,而不是頭。請參閱webResource.header(name,value) – slipperyseal
另外我發現在第一個代碼示例中使用了'https:// api.esios.ree.es/archives',並且在https://api.esios.ree.es/archive '在第二個 –
如果該令牌很敏感,您可能不想將其發佈到代碼 – slipperyseal