Advertisement
Guest User

Untitled

a guest
Jul 26th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.security.NoSuchAlgorithmException;
  6.  
  7. import javax.net.ssl.HttpsURLConnection;
  8. import javax.net.ssl.SSLContext;
  9.  
  10. public class Prog {
  11.  
  12.     public static void main(String[] args) throws Exception {
  13.         makeRequest();
  14.     }
  15.  
  16.     public static void makeRequest() throws Exception {
  17.  
  18.         String url = "https://test-as.sgx.trustedservices.intel.com:443/attestation/sgx/v2/sigrl/00000010";
  19.         URL target = new URL(url);
  20.  
  21.         /* Force TLSv1.2 */
  22.         SSLContext sc = SSLContext.getInstance("TLSv1.2");
  23.         sc.init(null, null, new java.security.SecureRandom());
  24.  
  25.         /* Set up HTTP properties. */
  26.         HttpsURLConnection connection = (HttpsURLConnection) target.openConnection();
  27.         connection.setSSLSocketFactory(sc.getSocketFactory());
  28.         connection.setRequestMethod("GET");
  29.         connection.setDoOutput(true);
  30.  
  31.         /* Obtain and check response status quote. */
  32.         int responseCode = connection.getResponseCode();
  33.  
  34.         /* Read response body into a String */
  35.         BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  36.         String inputLine;
  37.         StringBuffer responseBuffer = new StringBuffer();
  38.         while((inputLine = in.readLine()) != null){
  39.             responseBuffer.append(inputLine);
  40.         }
  41.         in.close();
  42.         String response = responseBuffer.toString();
  43.  
  44.         /* Evaluate result and print messages. */
  45.         System.out.println("HTTP response status code: " + responseCode + "\n");
  46.         System.out.println(response);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement