예제 #1
0
 public static String RetrieveFromServerPOST(String query, List<NameValuePair> nameValuePairs) {
   HttpClient httpClient = new DefaultHttpClient();
   HttpPost request = new HttpPost(query);
   try {
     request.addHeader("content-type", "text/html");
     request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     HttpResponse response = httpClient.execute(request);
     int statusCode = response.getStatusLine().getStatusCode();
     if (statusCode >= 200) return EntityUtils.toString(response.getEntity());
     else return null;
   } catch (Exception ex) {
     Shared.logError(ex.getMessage());
     return null;
   }
 }
예제 #2
0
  public static Contact getContact(String phone) {
    String query = null;
    try {
      query = getBaseUrl() + "/study/gcmcontact.php";
    } catch (Exception ex) {
      Shared.logError(ex.getMessage());
    }

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    nameValuePairs.add(new BasicNameValuePair("ph", phone));

    String responseData = RetrieveFromServerPOST(query, nameValuePairs);
    if (responseData != null && !responseData.isEmpty()) {
      return ParseContactFromResponse(responseData);
    }
    return null;
  }
예제 #3
0
 public static Boolean saveContact(String contactName, String phoneNumber, String regKey) {
   HttpClient httpClient = new DefaultHttpClient();
   HttpPost request = new HttpPost(getBaseUrl() + "/study/gcmreceiver.php");
   try {
     request.addHeader("content-type", "text/html");
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
     nameValuePairs.add(new BasicNameValuePair("ph", phoneNumber));
     nameValuePairs.add(new BasicNameValuePair("cn", contactName));
     nameValuePairs.add(new BasicNameValuePair("rk", regKey));
     request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     HttpResponse response = httpClient.execute(request);
     int statusCode = response.getStatusLine().getStatusCode();
     String responseBody = EntityUtils.toString(response.getEntity());
     if (statusCode >= 200) return true;
     else return false;
   } catch (Exception ex) {
     Shared.logError(ex.getMessage());
     return false;
   }
 }
예제 #4
0
  private static String RetrieveFromServer(String query) {
    try {
      HttpClient client = new DefaultHttpClient();
      HttpGet request = new HttpGet(query);
      HttpResponse response = client.execute(request);
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode >= 200) {
        BufferedReader rd =
            new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
          result.append(line);
        }
        return result.toString();
      }
    } catch (Exception ex) {
      Shared.logError("Error in retrieving data from server database!");
    }
    return null;
  }