0

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.

8
  • Please post your PHP code Commented Dec 10, 2013 at 10:47
  • i added the code but it is not being displayed. my code is <?php echo "kunal"; ?> Commented Dec 10, 2013 at 10:52
  • Btw your IP is a local address. Commented Dec 10, 2013 at 11:29
  • yes my ip is local addderess of my machine Commented Dec 10, 2013 at 11:37
  • your code seems to be ok, might be you are making mistake in getting data, have look here stackoverflow.com/questions/15569689/… Commented Dec 10, 2013 at 11:57

2 Answers 2

1

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) {
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try to open your url:

http://10.10.2.26/demo

With your phone browser. Probably you are not in the same network.

1 Comment

i am currently running on my laptop on emulator. and the url is executing on my phone browser correctly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.