Tuesday, 2 July 2013
Simple Webservice code for android
public class WebServices {
static String str;
static String postURL = "http://173.201.63.20/kerala_mobileapps/keralaapp.php";
static String response;
public static String dataFetech(String idPassed) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("mode",idPassed));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
response=EntityUtils.toString(resEntity);
response=response.trim();
System.out.println("response="+response);
}catch (IOException e) {
e.printStackTrace();
}
return response;
}
public static String searchResult(String companyname,String locationid,String cityid,String catid,String subcatid) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name",companyname));
params.add(new BasicNameValuePair("category_id",catid));
params.add(new BasicNameValuePair("subcategory_name",subcatid));
params.add(new BasicNameValuePair("state_id",locationid));
params.add(new BasicNameValuePair("city_id",cityid));
params.add(new BasicNameValuePair("method","searchresult"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
response=EntityUtils.toString(resEntity);
response=response.trim();
System.out.println("response from search results="+response);
}catch (IOException e) {
e.printStackTrace();
}
return response;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment