0

I want to consume a GET REST web service from java. It is an HTTPS connection. From postman, I can set the access token and SSL verification false. But if I want to do the same thing from a java class, how can I do that?

  1. How to make SSL verification false in java?
  2. How to set the access token in java while making calls to a REST web service?

I am using the below code:

URL url = new URL("https://apigateway.demo.int/demo/application/content");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP Error code : "
                    + conn.getResponseCode());
        }
pan1490
  • 939
  • 1
  • 7
  • 25
  • @user16320675 Could you provide me the site please – pan1490 Jul 20 '21 at 07:58
  • this one should give you some ideas https://stackoverflow.com/a/33104839/1338732 there are also other code snippets here @ SO - just use the search box – divadpoc Jul 20 '21 at 08:14
  • regarding question 2 - access token - they are usually passed via header field, but there are different types and conventions - some information can be found here: https://www.baeldung.com/java-http-url-connection – divadpoc Jul 20 '21 at 08:22
  • just a side-note: I prefer using [Java's HttpClient](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html) – divadpoc Jul 20 '21 at 08:24

0 Answers0