diff --git a/src/main/java/com/github/sardine/impl/SardineImpl.java b/src/main/java/com/github/sardine/impl/SardineImpl.java index 53ef7c25..1e9513bf 100644 --- a/src/main/java/com/github/sardine/impl/SardineImpl.java +++ b/src/main/java/com/github/sardine/impl/SardineImpl.java @@ -371,8 +371,8 @@ public void enablePreemptiveAuthentication(String hostname, int httpPort, int ht // Generate Basic preemptive scheme object and stick it to the local execution context BasicScheme basicAuth = new BasicScheme(credentialsCharset); // Configure HttpClient to authenticate preemptively by prepopulating the authentication data cache. - cache.put(new HttpHost(hostname, httpPort, "http"), basicAuth); - cache.put(new HttpHost(hostname, httpsPort, "https"), basicAuth); + cache.put(new HttpHost(hostname, httpPort == -1 ? 80 : httpPort, "http"), basicAuth); + cache.put(new HttpHost(hostname, httpsPort == -1 ? 443 : httpsPort, "https"), basicAuth); } @Override