tags:

views:

44

answers:

1

How to create an Http Connection to retrive a web page content to my android? Please post example code for this.

+1  A: 

Its http client,get example it might help

    HttpClient client;
    HttpGet method;
    String url;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    url="enter your url here";
    method = new HttpGet(url);
    try {
            client.execute(method);


        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
           setContentView(R.layout.main);
}
public void executeHttpGet() throws Exception {
    BufferedReader in = null;
    try {
        client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(new URI(url));
        HttpResponse response = client.execute(method);
        in = new BufferedReader
        (new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line + NL);
        }
        in.close();
        String page = sb.toString();
        System.out.println(page);
        } finally {
        if (in != null) {
            try {
                in.close();
                } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

it access XML data in preview i have this example try.

ud_an
am getting as an xml data in the phone so how to convert into real data with out the xml tags?
mohammedsuhail
i hvnt tried that look up here i think this help you.http://www.ibm.com/developerworks/opensource/library/x-android/index.html
ud_an
thanks for the answer
mohammedsuhail