All I need to to do is to connect via https. Must I use commons client for this?
+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
2010-05-02 01:45:31
Yup, that's it.
BalusC
2010-05-02 01:47:40
Oh, in real you'd like to take the character encoding from the request header first and then feed it to `InputStreamReader`.
BalusC
2010-05-02 01:53:00