1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| [...]
String res = null;
String enc_1 = URLEncoder.encode("{");
String enc_2 = URLEncoder.encode("}");
String enc_3 = URLEncoder.encode("'");
String type = enc_1 + "s:alpha" +enc_2 ;
String columns = enc_1 +"id_cl,hour,date,page"+enc_2 ;
String period = enc_1 +"D:"+enc_1 +"start:"+enc_3+"2020-01-01"+enc_3+",end:"+enc_3+"2020-02-01"+enc_3 + enc_2 + enc_2 ;
String request = "monUrl/getData?"
+ "&type=" + type
+ "&columns=" + columns
+ "&period=" +period;
try {
Client client = Client.create();
WebResource r = client.resource(request);
r.header("x-api-key", "xxxx_xxxxxxxx");
r.accept("application/json");
ClientResponse response = r.get(ClientResponse.class);
if (response.getStatus() != 200) {
LOG.severe("Erreur de requête:" + request + "(code:"+ response.getStatus() + ")");
return null;
}
res = response.getEntity(String.class);
} catch (Exception e) {
LOG.severe("Erreur de webservice:" + request + e.getMessage());
return null;
}[...] |
Partager