hello folks, i am new to android... I want to connect with server .Like i want to sent data and recieve data from server through Http Connection.. Can anyone help me how to do this. Can anyone provide me the sample of both side-client as well as server side. Thanks in advance...
+1
A:
I'm just starting reading about Android, but I'll throw in my two cents here. Apparently Android uses Apache HTTPComponents library to do what you are looking to do. You should check out the HttpClient tutorials here: http://hc.apache.org/
I hope that helps.
Mike Williamson
2010-04-06 07:29:26
Hi Sleepycat,thnks a lot for this file.Can you provide something same like this for android with samples.
remish
2010-04-07 10:29:04
Hey Remish, like I said I am just reading about this now. The book I am reading is "Beginning Android 2" from Apress. Its a great book.
Mike Williamson
2010-04-07 11:44:21
A:
Quick working example using Apache HTTPComponents:
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.google.com");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String reqData = httpclient.execute(httpget, responseHandler).toString();
httpclient.getConnectionManager().shutdown();
handler.sendEmptyMessage(0);
} catch (ClientProtocolException e) {
handler.sendEmptyMessage(1);
} catch (IOException e) {
handler.sendEmptyMessage(1);
}
private Handler handler = new Handler() { public void handleMessage(Message msg) {
switch (msg.what) { case 0: { // all ok, process data } break; case 1: { // show some errors } break; } } };
Alexandru Mos
2010-04-06 08:42:16
Hi Alexandru Mos,thnks for the reply.Can you tell me what is handler here " handler.sendEmptyMessage(0);" because it is giving error.
remish
2010-04-07 10:24:23
Uhhh... sorry, I forget about the handler. Take a look here, http://commons.apache.org/io/description.html
Alexandru Mos
2010-04-07 10:41:34
Can you give me your email id so that i can contact you directly,if you dont have any prob
remish
2010-04-07 11:01:20
Hi i did like this bt google.com is not opening..public class WebToolKit extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
remish
2010-04-07 11:20:55
HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://www.google.com"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { String reqData = httpclient.execute(httpget, responseHandler).toString(); httpclient.getConnectionManager().shutdown(); handler.sendEmptyMessage(0); } catch (ClientProtocolException e) { handler.sendEmptyMessage(1); } catch (IOException e) {
remish
2010-04-07 11:21:33
handler.sendEmptyMessage(1); } } private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 0: { // all ok, process data } break; case 1: { // show some errors } break; } } }; }
remish
2010-04-07 11:22:20