Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:46:17+00:00 2026-06-01T05:46:17+00:00

What are the differences if I try to connect to an https using HttpURLConnection

  • 0

What are the differences if I try to connect to an “https” using HttpURLConnection and HttpsURLConnection?

I was able to connect to “https” using both HttpURLConnection and HttpsURLConnection so I am confused. I thought I can only establish a connection to an “https” if I used HttpsURLConnection?

Below are some of my questions:

  • If I was able to open a connection to an “https” using HttpURLConnection, is my connection still in “https” or does it become “http”?
  • How about the validating of certificates? Since I didn’t any SSLSocketFactory and HostnameVerifier on my HttpURLConnection while connecting to an “https”, what SSLSocketFactory and HostnameVerifier am I using?
  • Does it mean that I am trusting everything regardless if the certificate is trusted or not?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:46:18+00:00Added an answer on June 1, 2026 at 5:46 am
    1. HTTPS connection being used.
    2. Default Behaviors
    3. Not sure but read below.

    I just wrote some code as a test (see all the way below). What ends up happening is the URL.openConnection() call will give you back a libcore.net.http.HttpsURLConnectionImpl class.

    This is an implementation of HttpsURLConnection but HttpsURLConnection inherits from HttpURLConnection. So you’re seeing polymorphism at work.

    Looking further into the debugger it appears that the class is using the default factory methods.

    hostnameVerifier = javax.net.ssl.DefaultHostnameVerifier

    sslSocketFactory = org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl

    Based on this it looks like the default behaviors are being used. I don’t know if that means if you’re trusting everything but you are definitely establishing an HTTPS connection.

    The documentation kinda hints at the connection will auto-trust CAs that are well known but not self-signed. (see below) I did not test this but they have example code on how to accomplish that here.

    If an application wants to trust Certificate Authority (CA)
    certificates that are not part of the system, it should specify its
    own X509TrustManager via a SSLSocketFactory set on the
    HttpsURLConnection.

    Runnable r = new Runnable() {
    
        public void run() {
            try {
            URL test = new URL("https://www.google.com/");
            HttpURLConnection connection = (HttpURLConnection) test.openConnection();
            InputStream is = connection.getInputStream();
            StringWriter sw = new StringWriter();
            String value = new java.util.Scanner(is).useDelimiter("\\A").next();
            Log.w("GOOGLE", value);
            } catch(Exception e) {
                Log.e("Test", e.getMessage());
            }
        }
    
    };
    
    Thread t = new Thread(r);
    t.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the differences between delegates and an events? Don't both hold references to
How can I add an encoding attribute to the body tag using Savon? Some
Using emacs on Ubuntu 11.10. I want to connect to a SQL Server database
i try to find the most efficient way for Facebook connect. after some search
I got a complex report using reporting service, the report connect to a SQl
Setup: Windows 7 64-bit Office 2010 Professional 64-bit Visual Studio 2010 Professional Using Connection
I try to understand the main differences between MVC / MVP and MVVM patterns.
I want to connect to multiple telnet hosts using threading in python, but I
What is the difference between try { } catch { throw; } and try
Syntax aside, what is the difference between try { } catch() { } finally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.