1 package com.example.bee_honeyt;
3 import android.os.AsyncTask;
4 import android.util.Log;
6 import java.io.BufferedInputStream;
7 import java.io.BufferedReader;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.io.InputStreamReader;
11 import java.io.StringReader;
12 import java.net.HttpURLConnection;
13 import java.net.MalformedURLException;
16 import javax.net.ssl.HttpsURLConnection;
30 private static final String
TAG =
"_Historique";
41 Log.d(
TAG,
"new Historique()");
59 Log.d(
TAG,
"estCharge() " + this.chargement);
69 public void charger(String strUrl, String key, String deviceID, String duree)
71 if(strUrl !=
null && !strUrl.isEmpty())
74 if(deviceID.isEmpty())
75 url = strUrl +
"/api/v2/query";
77 url = strUrl +
"/api/v2/query/" + deviceID;
79 url +=
"?last=" + duree;
80 Log.d(
TAG,
"charger() " + strUrl);
82 tache.execute(url, key);
93 Log.d(
TAG,
"<AsyncTaskHTTP> new AsyncTaskHTTP()");
100 HttpsURLConnection connexionHTTPS =
null;
101 InputStream in =
null;
102 String contenu =
null;
104 Log.d(
TAG,
"<AsyncTaskHTTP> doInBackground() url : " + strings[0] +
" - key : " + strings[1]);
107 url =
new URL(strings[0]);
108 connexionHTTPS = (HttpsURLConnection) url.openConnection();
109 connexionHTTPS.setRequestProperty(
"Accept",
"application/json");
110 connexionHTTPS.setRequestProperty(
"Authorization",
"key " + strings[1]);
111 int codeReponse = connexionHTTPS.getResponseCode();
112 if (codeReponse != HttpURLConnection.HTTP_OK)
114 Log.d(
TAG,
"<AsyncTaskHTTP> Erreur code réponse = " + codeReponse);
118 in =
new BufferedInputStream(connexionHTTPS.getInputStream());
119 BufferedReader r =
new BufferedReader(
new InputStreamReader(in));
120 StringBuilder sb =
new StringBuilder();
126 if (!((ligne = r.readLine()) !=
null))
129 catch (IOException e)
136 contenu = sb.toString();
137 Log.d(
TAG,
"<AsyncTaskHTTP> données récupérées : " + contenu.length() +
" octet(s)");
139 catch (MalformedURLException e)
141 Log.d(
TAG,
"MalformedURLException");
144 catch (IOException e)
146 Log.d(
TAG,
"IOException");
151 if (connexionHTTPS !=
null)
152 connexionHTTPS.disconnect();
161 Log.d(
TAG,
"<AsyncTaskHTTP> onPostExecute()");
172 StringReader sin =
new StringReader(contenu);