Reputation: 19
I am calling php url from android to recevive some string value.
My android code is as below:
private static final String BASE_URL="http://10.10.2.26/demo";
public static HttpResponse executeUrl(String action,String[] parameters) {
try {
HttpClient client = new DefaultHttpClient();
URI website = new URI(BASE_URL+"/"+action);
System.out.println("serverurl="+website);
HttpGet request = new HttpGet();
request.setURI(website);
System.out.println("5");
HttpResponse response = client.execute(request);
System.out.println("no error in execute URL");
return response;
} catch (Exception e) {
System.out.println("In error of execute URL"+e.getLocalizedMessage());
}
return null;
}
Following is my php code:
<?php
echo "kunal";
?>
after execution i receive null to android.
Upvotes: 0
Views: 1486
Reputation: 96
Code for retrieving values from php. It is working fine.
private void get_valueFromPhp(String php) {
String responseString = null;
try{
HttpClient httpclient = new DefaultHttpClient();
String url ="your url";
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
Toast.makeText(getApplicationContext(),responseString,1000).show();
} catch(Exception e) {
}
}
Upvotes: 1
Reputation: 738
Try to open your url:
http://10.10.2.26/demo
With your phone browser. Probably you are not in the same network.
Upvotes: 1