在对java.net.URL的不同调用之间保持身份验证

时间:2014-05-08 16:14:58

标签: java url jenkins hudson

我有一个使用基本身份验证(HTTP)的远程服务器,我需要多次调用不同的URL。呼叫的一个例子:

URL address = new URL ("hhtp://localhost:8080");
HttpURLConnection connection;
// open connection
connection = (HttpURLConnection) address.openConnection();
String encoding = DatatypeConverter.printBase64Binary((username + ":" + password).getBytes());
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + encoding);
// transform result code into an exception
int code = connection.getResponseCode();
if ((code < 200) || (code >= 300))
{
       throw new HttpRetryException(connection.getResponseMessage(), code, address.toString());
}
 return connection;

问题似乎是服务器花了很多时间来验证用户身份。在第一次调用之后,我们需要另一个页面(不同的URL)到同一个服务器。如何在不同的电话之间保持会话?

编辑:

澄清一下,我试图连接到Jenkins服务器。

0 个答案:

没有答案