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. ProgressDialog during location tasks either won't show or force closes - I have tried everything!

ProgressDialog during location tasks either won't show or force closes
- I have tried everything!

I now have it in a Handler with a full 1 second delay (one method
another post suggested) but it doesn't show.  I simply am stuck.
Threads are usually force closing when I use those methods.

What other tricks are there for this?

Thanks!

-- 

2. Suppressing touch events with ACTION_CANCEL

Hi,

I am suppressing the touch events depending upon the size in the
dispatchTouchEvent of View.java. If the event size is greater than the
threshhold i m sending the event as ACTION_CANCEL to onTouchEvent. I
wanted to know how ACTION_CANCEL works. In the android document it
says it cancel the current gesture. What is the meaning of gesture (is
it  ACTION_DOWN plus something which can happen between ACTION_UP) or
is it individual event like ACTION_DOWN, ACTION_UP or ACTION_MOVE ?

Thanks in advance.

Rahul

-- 

3. Better Keyboard 4.1

4. Questions about data persistence

5. How to draw lines through onTouchEvent

6. On distribution of APP

7. Sony Ericsson Developer World on Android Developers