Search code examples
javahttpclient

Determine if HttpPost is instance of https


how to determine if the connection is instance of https?

        HttpPost httpPost = new HttpPost(requestParameter.getHostUrl());
        httpPost.setEntity(new StringEntity(requestParameter.getRequest()));
        httpPost.setHeader(CONTENT_TYPE, requestParameter.getContentType());

Because I remember in HttpURLConnection you can do something like:

   URL url;
   url = new URL(endpoint);

    HttpURLConnection con;
    try {
        con = (HttpURLConnection) url.openConnection();
    } catch (IOException e) {

    }

    // you can do something like:
    if (con instanceof HttpsURLConnection) 

Solution

  • Looks like you can do

    HttpPost httpPost = new HttpPost(requestParameter.getHostUrl());
    
    httpost.getURI().getScheme();