Esempio n. 1
0
 public String httpGet(String urlStr) {
   URL url = null;
   HttpURLConnection conn = null;
   Message msg = handler.obtainMessage();
   ;
   try {
     url = new URL(urlStr);
     conn = (HttpURLConnection) url.openConnection();
     conn.setRequestMethod("GET");
     conn.setConnectTimeout(5000);
     conn.setReadTimeout(5000);
     conn.connect();
     if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
       String result = StreamUtil.getStringFromInputStream(conn.getInputStream());
       return result;
     } else if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
       msg.what = VictorApplication.CODE_URL_NOT_FOUND;
       msg.arg1 = 11111;
       handler.sendMessage(msg);
     }
   } catch (MalformedURLException e) {
     msg.what = VictorApplication.CODE_URL_ERROR;
     msg.arg1 = 11111;
     handler.sendMessage(msg);
     e.printStackTrace();
   } catch (IOException e) {
     msg.what = VictorApplication.CODE_NET_ERROR;
     msg.arg1 = 11111;
     handler.sendMessage(msg);
     e.printStackTrace();
   }
   return null;
 }