i want to send data from android application to local server (PHP) but it doesn't work this is my code (it is work with remote server ):

String path ="http://localhost/sd.php"; HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 100000);

HttpResponse response;

        JSONObject json = new JSONObject();
        try {
            HttpPost post = new HttpPost(path);

            json.put("im", 999);
            json.put("cTime", 12);
            Log.i("jason Object", json.toString());
            post.setHeader("json", json.toString());
            StringEntity se = new StringEntity(json.toString());
            se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
            post.setEntity(se);

            response = client.execute(post);


        } catch (Exception e) {
            Object n=e.getStackTrace();
            Toast.makeText( getApplicationContext(),n.toString(),Toast.LENGTH_SHORT).show();
        } 

i thing the wrong in the address http://localhost/sd.php pleas help me to find a solution to this problem

link|improve this question

67% accept rate
I guess by "local" you mean "on the emulator's host machine"... That won't be "local" on a real phone. – Seva Alekseyev Mar 27 '11 at 19:16
yes ,it on the emulator – m7m Mar 27 '11 at 19:21
feedback

1 Answer

up vote 2 down vote accepted

You need the IP address of the server. Localhost from the app is the phone.

link|improve this answer
How can i get the IP address of the server(it is local server)? – m7m Mar 27 '11 at 19:18
On the server type ifconfig if using a Mac or Unix box. ipconfig in Windows. – Justin Thomas Mar 27 '11 at 19:21
yesss it's work now...thanx allot – m7m Mar 27 '11 at 19:40
Mark my answer as correct and upvote please :) – Justin Thomas Mar 27 '11 at 19:42
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.