Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== --- java/org/apache/commons/httpclient/HttpMethodBase.java (revision 167889) +++ java/org/apache/commons/httpclient/HttpMethodBase.java (working copy) @@ -1176,7 +1176,11 @@ } CookieSpec matcher = getCookieSpec(state); - Cookie[] cookies = matcher.match(conn.getHost(), conn.getPort(), + String host = this.params.getVirtualHost(); + if (host == null) { + host = conn.getHost(); + } + Cookie[] cookies = matcher.match(host, conn.getPort(), getPath(), conn.isSecure(), state.getCookies()); if ((cookies != null) && (cookies.length > 0)) { if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) { @@ -1468,12 +1472,16 @@ } CookieSpec parser = getCookieSpec(state); + String host = this.params.getVirtualHost(); + if (host == null) { + host = conn.getHost(); + } for (int i = 0; i < headers.length; i++) { Header header = headers[i]; Cookie[] cookies = null; try { cookies = parser.parse( - conn.getHost(), + host, conn.getPort(), getPath(), conn.isSecure(), @@ -1490,7 +1498,7 @@ Cookie cookie = cookies[j]; try { parser.validate( - conn.getHost(), + host, conn.getPort(), getPath(), conn.isSecure(),