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
2010-08-26 12:55:29
am getting as an xml data in the phone so how to convert into real data with out the xml tags?
mohammedsuhail
2010-08-31 05:42:36
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
2010-08-31 06:08:48
thanks for the answer
mohammedsuhail
2010-09-02 06:54:18