Posted By

cha0s on 10/06/10


Tagged

get http java http-client


Versions (?)

Http-Client GET


 / Published in: Java
 

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

  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  

You need to login to post a comment.