Problem in Http Get Method..pls tell me..

by ragavendran s » Wed, 02 Sep 2009 22:12:17 GMT


Sponsored Links
 can u tell me how to send the Url to the server using Http Get method...

Here i m trying to insert a name into the databse .If i execute the below

showing code  there it tells "Connection to  http:localhost refused "

 i think the error is is in the Http method ..Would u tel me pls how to
Correct
it....


With ragards,

Raghav.S



My Code:


package simpl.http1;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class simplhttp1 extends Activity {
    /** Called when the activity is first created. */


    Button enter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        enter=(Button)findViewById(R.id.enter1);


        enter.setOnClickListener(new OnClickListener(){

            public void onClick(View v)
            {

                openconn();


            }
        });



    }

   public void openconn()

   {

                 String str11="murugan";
               String feed_url="
http://localhost:8080/Serv1/servlet/Servlet1?st1="+str11;
              HttpClient client=new DefaultHttpClient();
              HttpGet siteRequest = new HttpGet(feed_url);
              try {
                HttpResponse httpResponse = client.execute(siteRequest);
                TextView t = (TextView) findViewById(R.id.myTextView);

                 t.setText("Ok");
            } catch (ClientProtocolException e) {

                TextView t = (TextView) findViewById(R.id.myTextView);
                t.setText(e.getMessage());
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                TextView t = (TextView) findViewById(R.id.myTextView);
                t.setText(e.getMessage());
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

   }



}

--~--~---------~--~----~------------~-------~--~----~



Problem in Http Get Method..pls tell me..

by Urs Grob » Wed, 02 Sep 2009 23:44:28 GMT


 localhost is the device itself, not your host where the emulator is running
on. If I remember correctly you would have to use 10.0.2.2 instead of
localhost.

-- Urs





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. What is drawable-hdpi, drawable-ldpi and drawable-mdpi ?

http://developer.android.com/guide/practices/screens_support.html




> 

2. Regarding the surfaceview

Hi,
   I am currently working on the app in which my media player class is
singleton, and i want to play the video files. I use surfaceView for the
video display part. But the problem i m facing is when i change the
orientation , the previous playback disappears (if was playing) and the new
surface view is  getting created ..but  the callback method surface created
is not getting called in which i want to take further action. Where am i
going wrong ?

Regards,
Ameya

-- 

3. How to disable pop up blocker in emulator 2.1

4. How to change target build on Android project?

5. Leaked Window changing orientation with SubMenu

6. SOLD WTS : Samsung Galaxy S Second

7. Mechanism for intercepting TCP/UDP traffic?