Using HttpPost to get data from local server
<p>I used following code in java class of android. Everything works except it wont send any request. Answer is always null.  </p>

<pre><code>    public class WebviewActivity extends Activity {
    /** Called when the activity is first created. */
EditText et; Editable ur;
TextView tx;HttpResponse response;String x;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tx=(TextView)findViewById(R.id.textView1);
    et=(EditText)findViewById(R.id.editText1);
    Button button = (Button)findViewById(R.id.button1);
    button.setOnClickListener(send);

}
private OnClickListener send = new OnClickListener() {
    public void onClick(View v) {
    ur=et.getText();
      postData();
     tx.setText("ans:"+x);

    }};

public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://localhost/name.php");

    try {
        // Add your data
        List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1);
        nameValuePairs.add(new BasicNameValuePair("name", ur.toString()));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
       response = httpclient.execute(httppost);
       Log.d("myapp", "response " + response.getEntity());
       x= EntityUtils.toString(response.getEntity());


    } catch (ClientProtocolException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }
}  }
</code></pre>

<p>and in php i used following code</p>

<pre><code>     &lt;?php
     $name=$_POST["name"];
      echo $name;
     ?&gt;
</code></pre>

<p>Any idea how it make it work?</p>
