views:

65

answers:

2

All I need to to do is to connect via https. Must I use commons client for this?

A: 

Yes. Just use the URL class and specify an HTTPS url.

GregS
+2  A: 

No, you don't have to, you can use a regular URLConnection. Something like this:

public class URLConnectionReader {

    public static void main(String[] args) throws Exception {
        URL url = new URL("https://jax-ws.dev.java.net/");
        URLConnection uc = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                                uc.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }
        in.close();
    }    
}

This may require a bit more work if the site you're connecting to uses a certificate that has not been signed by a well known CA or a self-signed certificate. But this is another story.

Pascal Thivent
Yup, that's it.
BalusC
Oh, in real you'd like to take the character encoding from the request header first and then feed it to `InputStreamReader`.
BalusC