Web Server Communication (WSC)

In the following example I will demonstrate who we can communicate with web server.

Step 1:  Import the following package:
import org.apache.http.*;

Step 2: Create the instance of HttpClient.
HttpClient agent = new DefaultHttpClient();

Step 3: Create instance of HttpGet.
HttpGet req = new HttpGet(“http://www.google.com/”);

Step 4: Invoke the request and get response.
HttpResponse res = agent.execute(req);

Step 5: Get response content.
res.getEntity().getContent(); //it will return the InputStream
Note: with the BufferedReaderyou can read the InputStream.

Share This Post

Recent Articles

© 2012 Android.PK Blog. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by Android.Pk ·