java.net.UnknownHostException
HejJeg prøver at lave en HttpConnection (via jakarta commens) og det virker fint, med alm. adresser, men så snart jeg prøver til en https (ssl) får jeg en java.net.UnknownHostException fejl.
Er der nogle som har en ide om hvad det kan skyldes?
Jeg bruger:
-java 1.4.2.xx
-hhv HttpClient og logging jar filer downloaded fra: http://jakarta.apache.org/site/binindex.cgi
Nedenfor er et lille kode eksempel, der virker fint med http kald, men kaster den omtalte fejl ved https kald:
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpState;
import java.security.Security;
public class HttpClientEksampel {
public HttpClientEksampel() {
System.setErr(System.out);
// add the provider
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// set the property
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
}
public void sendPOSTRequest(String proxyIP, int proxyPort, String destIP, int destPort, boolean useHttps) {
HttpConnection httpsCon = null;
try {
if (useHttps && proxyIP == null) {
httpsCon = new HttpConnection(destIP, destPort, useHttps);
} else if (proxyIP != null) {
httpsCon = new HttpConnection(proxyIP, proxyPort, destIP, destPort, useHttps);
} else {
httpsCon = new HttpConnection(destIP, destPort);
}
httpsCon.open();
org.apache.commons.httpclient.methods.GetMethod postMethod = new org.apache.commons.httpclient.methods.GetMethod();
HttpState https = new HttpState();
postMethod.setFollowRedirects(true);
postMethod.execute(https, httpsCon);
System.out.println(postMethod.getStatusText());
System.out.println(postMethod.getResponseBodyAsString());
} catch (Throwable t) {
System.out.println(" Exception:" + t.getMessage());
t.printStackTrace();
} finally {
if (httpsCon != null && httpsCon.isOpen())
httpsCon.close();
}
}
public static void main(String[] args) {
HttpClientEksampel httpClientEksampel = new HttpClientEksampel();
httpClientEksampel.sendPOSTRequest(null,-1,"www.jp.dk", 80, false); //virker
httpClientEksampel.sendPOSTRequest(null,-1,"netbank.danskebank.dk/html/index.html?site=DBNB", 443, true); //virker ikke
}
}
