SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package library;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5.  
  6. import javax.swing.JOptionPane;
  7. import javax.ws.rs.core.MediaType;
  8.  
  9. import org.apache.http.HttpHeaders;
  10. import org.apache.http.HttpResponse;
  11. import org.apache.http.client.HttpClient;
  12. import org.apache.http.client.config.RequestConfig;
  13. import org.apache.http.client.methods.HttpGet;
  14. import org.apache.http.client.methods.HttpPut;
  15. import org.apache.http.impl.client.HttpClientBuilder;
  16. import org.apache.http.impl.client.HttpClients;
  17.  
  18. public class clientGet {
  19.    
  20.     public static void main(String[] args) throws Exception {
  21.        
  22.         String url = "http://localhost:8080/LibraryServer/livres";
  23.         HttpClient client = HttpClients.createDefault();
  24.         HttpGet request = new HttpGet(url);
  25.         request.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
  26.         HttpResponse response = client.execute(request);
  27.         System.out.println(response.getStatusLine().getStatusCode());
  28.         BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  29.         String line = br.readLine();
  30.         while(line!=null) {
  31.             System.out.println(line);
  32.             line = br.readLine();
  33.         }
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top