static Data da = ConfigurationActivity.d;
private static String mail;
public static String getMailAddress() throws SQLException {
da.open();
Cursor c = null;
c = da.fetchConfiguration();
mail = c.getString(1);
Log.i("EmailProxy","Mail: "+mail);
c.close();
da.close();
return mail;
}
public static String getEntities(String Url, HashMap
String response=null;
try{
//String q = Url.trim()+generateQueryString(params);
response = sendRequest(Url.trim()+generateQueryString(params));
}/*catch(ServerExecutionException e){
throw e;
}*/catch(Exception e){
return response;
}
return response;
}
private static String generateQueryString(HashMap
{
if(params==null)
return "";
Set
StringBuilder queryString = new StringBuilder();
queryString.append("?");
for(String key:keys)
{
String value=params.get(key);
if(value!=null)
value=value.replaceAll(" ", "%20");
queryString.append(key).append("=").append(value).append("&");
}
String requestString=queryString.toString().substring(0, queryString.toString().length()-1);
return requestString;
}
private static String sendRequest(String weburl)throws Exception{
Log.i("Url",weburl);
String responseText="";
HttpClient client = new DefaultHttpClient();
HttpResponse response = null;
Log.i("Request Url is",weburl);
//HttpGet getMethod = new HttpGet(weburl);
HttpPost getMethod = new HttpPost(weburl);
Log.i("GetMethod",getMethod.toString());
client.getParams().setParameter("http.connection.timeout", new Integer(10000));
response = client.execute(getMethod);
Log.i("respose",response.toString());
try{
InputStream in = response.getEntity().getContent();
responseText = getStringFromInputStream(in);
}catch(Exception e){
Log.i("Exception",e.getMessage());
throw new Exception("Some Error Has occured.");
}
return responseText;
}
private static String getStringFromInputStream(InputStream in) {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
String line="";
try {
while((line=reader.readLine())!=null){
buffer.append(line).append(System.getProperty("line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
}
return buffer.toString();
}
No comments:
Post a Comment