code: public static OCSPResp getOCSPResponce(String serviceUrl, OCSPReq request) throws CertificateVerificationException {
  
          try {
              byte[] array = request.getEncoded();
              if (serviceUrl.startsWith("http")) {
                  HttpURLConnection connection;
                  URL url = new URL(serviceUrl);
                  connection = (HttpURLConnection) url.openConnection();
                  connection.setRequestProperty("Content-Type", "application/ocsp-request");
                  connection.setRequestProperty("Accept", "application/ocsp-response");
                  connection.setDoOutput(true);
                  try (OutputStream out = connection.getOutputStream();
                          DataOutputStream dataOut = new DataOutputStream(new BufferedOutputStream(out))) {
  
                      dataOut.write(array);
  
                      dataOut.flush();
  
                      //Check errors in response:
                      if (connection.getResponseCode() / 100 != 2) {
                          throw new CertificateVerificationException(
                                  "Error getting ocsp response." + "Response code is " + connection.getResponseCode());
                      }
  
                      //Get Response.
                      InputStream in = (InputStream) connection.getContent();
                      return new OCSPResp(in);
                  }
              } else {
                  throw new CertificateVerificationException("Only http is supported for OCSP calls");
              }
          } catch (IOException e) {
              throw new CertificateVerificationException("Cannot get OCSP Response from url: " + serviceUrl, e);
          }
      }
docs: Gets an ASN.1 encoded OCSP response (as defined in RFC 2560) from the given service URL. Currently supports
  only HTTP.
  
  @param serviceUrl URL of the OCSP endpoint.
  @param request An OCSP request object.
  @return OCSP response encoded in ASN.1 structure.
  @throws CertificateVerificationException if any error occurs while trying to get a response from the CA.