Q:

Java and HttpsUrlConnection ignoring ssl certificates

1)I am trying to consume https url by ignoring ssl certificates
2)I have tried to hit https url request to Google Geolocation api url but I am getting below response indicating I am making wrong program.
Because I tried the url via Postman and it shows correct output.
HttpResponseProxy{HTTP/1.1 404 Not Found [Cache-Control: no-cache, no-store, max-age=0, must-revalidate, Pragma: no-cache, Expires: Mon, 01 Jan 1990 00:00:00 GMT, Date: Sun, 26 Nov 2017 07:38:48 GMT, Vary: Origin, Vary: X-Origin, Content-Type: text/html; charset=UTF-8, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-XSS-Protection: 1; mode=block, Server: GSE, Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", Transfer-Encoding: chunked] org.apache.http.client.entity.DecompressingEntity@5c18298f}

I have also used other sources but could not find out the hint for the same.
Here is my Code
public void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect()
    throws Exception {
String HOST_WITH_SSL="https://www.googleapis.com/geolocation/v1/geolocate?key=XXX";
SSLContext sslContext = new SSLContextBuilder()
        .loadTrustMaterial(null, (certificate, authType) -> true).build();

CloseableHttpClient client = HttpClients.custom()
        .setSSLContext(sslContext)
        .setSSLHostnameVerifier(new NoopHostnameVerifier())
        .build();
HttpGet httpGet = new HttpGet(HOST_WITH_SSL);
httpGet.setHeader("Accept", "application/json");

HttpResponse response = client.execute(httpGet);
System.out.println(response);
}

Can anyone guide how to hit https url correctly?

A:

The URL in the code requires a POST request and you are sending a GET.
With a GET request it returns 404 even in Postman.
Changing the code to use HttpPost solves your problem.
Google has a valid certificate, you probably should not try ignore certificates though.

