Sending an HTTPS request from a Java application


What are the ways to send https requests from a desktop java application? Of particular interest is the source code example.


The most primitive way is to use URLConnection . Here is an example without error handling, encodings and other husks:

public static void main(String[] args) throws Exception {
    URLConnection connection = new URL("").openConnection();

    InputStream is = connection.getInputStream();
    InputStreamReader reader = new InputStreamReader(is);
    char[] buffer = new char[256];
    int rc;

    StringBuilder sb = new StringBuilder();

    while ((rc = != -1)
        sb.append(buffer, 0, rc);



In case it turns out that the standard URLConnection (more precisely, in fact, HttpsUrlConnection is created) cannot do something, then use the Apache HTTP Client .

Scroll to Top