Looking at your code, it seems that you print the String variable
Output. This variable contains the value of the URL but you never set
it to anything else. I think you want to set a variable to the return
value of your downloadUrl method.

And some unasked advice with regards to dealing with the retrieving of
the http content. I retrieve the data directly with the HttpEntity
class as followed:

(I use a Post because i use it to post data to a external server, but
it works the same)


HttpPost siteRequest = new HttpPost(url);

HttpResponse httpResponse = client.execute(dataRequest);

responseData = EntityUtils.toString(httpResponse.getEntity());

After this responseData contains the http content retrieved from the
request.

On Aug 31, 9:30 am, ragavendran s <sraghav.ra...@gmail.com> wrote:
> Can anyone tell what is the problem in the given code to retrieve
>
>  the data from the local server by using Http Get method......pls give some
>
> example code......i tried but if i give the url the result i m getting same
> url
>
> in the text view...shall any one point out wat the error in the code........
>
> pls point out the errors...
>
> With regards,
> Raghav.S
>
> package req.http1;
>
> import java.io.IOException;
> import java.io.InputStream;
> import org.apache.http.HttpResponse;
> import org.apache.http.client.HttpClient;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.client.methods.HttpRequestBase;
> 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.EditText;
> import android.widget.TextView;
>
> public class reqhttp extends Activity {
>     TextView text;
>      EditText edt;
>      Button btn;
>      String n=null;
>      String contentOfMyInputStream1;
>      String output = null;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         edt=(EditText)findViewById(R.id.edt);
>         text=(TextView)findViewById(R.id.text);
>         btn=(Button)findViewById(R.id.btn);
>
>         btn.setOnClickListener(new OnClickListener() {
>             public void onClick(View v) {
>             text.setText("");
>             // Thread thread = new Thread();
>              String st1;
>
>              st1=edt.getText().toString();
>             //thread.start();
>
>             try {
>                  output ="http://localhost:8080/Serv1/servlet/Servlet1?st1=
> "+st1;
>                 downloadUrl(output);
>             } catch (IOException e) {
>                 // TODO Auto-generated catch block
>                 e.printStackTrace();
>             }
>             if (output != null)
>             {
>                 text.setText(output);
>             }
>
>             }
>             });
>
>     }
>
>     public String downloadUrl(String url) throws  IOException{
>         HttpClient httpclient = new DefaultHttpClient();
>         HttpRequestBase httpRequest = null;
>         HttpResponse httpResponse = null;
>         InputStream inputStream = null;
>         String response = "";
>         StringBuffer buffer = new StringBuffer();
>
>         httpRequest = new HttpGet(url);
>
>         httpResponse = httpclient.execute(httpRequest);
>         inputStream = httpResponse.getEntity().getContent();
>         int contentLength = (int)
> httpResponse.getEntity().getContentLength();
>         if (contentLength < 0){
>            // Log.e(TAG, "The HTTP response is too long.");
>         }
>         byte[] data = new byte[256];
>         int len = 0;
>         while (-1 != (len = inputStream.read(data)) )
>         {
>             buffer.append(new String(data, 0, len));
>         }
>
>         inputStream.close();
>
>         response = buffer.toString();
>
>         return response;
>
>     }
>
>
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to