Http-Client GET


/ Published in: Java
Save to your folder(s)

Required libraries: http://hc.apache.org/downloads.cgi


Copy this code and paste it in your HTML
  1. package yourpackage;
  2.  
  3. import java.io.IOException;
  4. import org.apache.http.HttpEntity;
  5. import org.apache.http.HttpResponse;
  6. import org.apache.http.HttpVersion;
  7. import org.apache.http.client.ClientProtocolException;
  8. import org.apache.http.client.HttpClient;
  9. import org.apache.http.client.methods.HttpGet;
  10. import org.apache.http.impl.client.DefaultHttpClient;
  11. import org.apache.http.params.CoreProtocolPNames;
  12.  
  13. public class HttpClientGetTest {
  14. public static void main(String[] args) throws IllegalArgumentException, IOException {
  15. get();
  16. }
  17.  
  18. private static void get() throws ClientProtocolException, IOException {
  19. HttpClient httpclient = new DefaultHttpClient();
  20. httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
  21.  
  22. HttpGet get = new HttpGet("your-url");
  23. HttpResponse response = httpclient.execute(get);
  24. HttpEntity resEntity = response.getEntity();
  25. int returnCode = response.getStatusLine().getStatusCode();
  26. }
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.