Posting Variables to webserver in android
<p>i want to post a variable to this file on webserver. i am using free hosting company.
<a href="http://locationmeter.comule.com/reg.php" rel="nofollow">http://locationmeter.comule.com/reg.php</a>
it is doing good on emulator but it is not working on device. here is the code</p>

<pre><code>public class MainActivity extends Activity {

    Button bSubmit;
    EditText name, age;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        // TODO Auto-generated method stub
        name = (EditText) findViewById(R.id.editText1);
        bSubmit = (Button) findViewById(R.id.button1);
        bSubmit.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                ArrayList&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
                NameValuePair param = new BasicNameValuePair("name", name
                        .getText().toString());
                params.add(param);
                try {
                    HttpPost httpPost = new HttpPost(
                            "http://locationmeter.comule.com/reg.php");
                    httpPost.setEntity(new UrlEncodedFormEntity(params));

                    HttpClient client = new DefaultHttpClient();
                    HttpResponse response = client.execute(httpPost);
                    InputStream is = response.getEntity().getContent();
                    BufferedReader br = new BufferedReader(
                            new InputStreamReader(is));
                    String line = br.readLine();
                    do {
                        Toast.makeText(getBaseContext(), line, 300).show();
                        Log.d("", "usmann" + line);
                        line = br.readLine();
                    } while (line != null);

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

            }
        });
    }

}
</code></pre>

<p>Manifest:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.postingvar"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="10" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET"/&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;
        &lt;activity
            android:name="com.example.postingvar.MainActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<p>reg.php</p>

<pre><code>     &lt;?php
            if (isset($_POST['name'])) {
                $res = "success";
                echo json

_encode($res);

        }else{
            $res = "failed";
            echo json_encode($res);
        }
    ?&gt;
</code></pre>

<p>from device i am getting a long html error page. please help</p>

<pre><code>usmann&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
03-24 10:40:19.185: D/(413): usmann&lt;html&gt;&lt;head&gt;
03-24 10:40:19.194: D/(413): usmann&lt;meta http-equiv="Content-Type" CONTENT="text/html; charset=utf-8"&gt;
03-24 10:40:19.215: D/(413): usmann&lt;title&gt;ERROR: The requested URL could not be retrieved&lt;/title&gt;
03-24 10:40:19.225: D/(413): usmann&lt;style type="text/css"&gt;&lt;!-- 
03-24 10:40:19.234: D/(413): usmann /*
03-24 10:40:19.246: D/(413): usmann Stylesheet for Squid Error pages
03-24 10:40:19.265: D/(413): usmann Adapted from design by Free CSS Templates
03-24 10:40:19.285: D/(413): usmann http://www.freecsstemplates.org
03-24 10:40:19.305: D/(413): usmann Released for free under a Creative Commons Attribution 2.5 License
03-24 10:40:19.315: D/(413): usmann*/
03-24 10:40:19.324: D/(413): usmann
03-24 10:40:19.335: D/(413): usmann/* Page basics */
03-24 10:40:19.355: D/(413): usmann* {
03-24 10:40:19.364: D/(413): usmann font-family: verdana, sans-serif;
03-24 10:40:19.375: D/(413): usmann}
03-24 10:40:19.395: D/(413): usmann
03-24 10:40:19.404: D/(413): usmannhtml body {
03-24 10:40:19.425: D/(413): usmann margin: 0;
03-24 10:40:19.435: D/(413): usmann padding: 0;
03-24 10:40:19.455: D/(413): usmann background: #efefef;
03-24 10:40:19.475: D/(413): usmann font-size: 12px;
03-24 10:40:19.495: D/(413): usmann color: #1e1e1e;
03-24 10:40:19.505: D/(413): usmann}
03-24 10:40:19.524: D/(413): usmann
03-24 10:40:19.555: D/(413): usmann/* Page displayed title area */
03-24 10:40:19.565: D/(413): usmann#titles {
03-24 10:40:19.595: D/(413): usmann margin-left: 15px;
03-24 10:40:19.614: D/(413): usmann padding: 10px;
03-24 10:40:19.636: D/(413): usmann padding-left: 100px;
03-24 10:40:19.654: D/(413): usmann background: url('http://www.squid-cache.org/Artwork/SN.png') no-repeat left;
03-24 10:40:19.665: D/(413): usmann}
03-24 10:40:19.686: D/(413): usmann
03-24 10:40:19.694: D/(413): usmann/* initial title */
03-24 10:40:19.716: D/(413): usmann#titles h1 {
03-24 10:40:19.725: D/(413): usmann color: #000000;
</code></pre>
