0

我需要从其他站点获取来自某个 Lotus 连接站点的数据,例如用户状态。我尝试通过java建立与lotus的连接,例如

> server = "https://" + path + param + "&format=full";
> URL profiles_url = new URL(server);
> // Open the URL: throws exception if not found
> HttpURLConnection profiles_conn = HttpURLConnection)profiles_url.openConnection();
> profiles_conn.connect();
> // Process the Atom feed in the response content
> readResponse(profiles_url.openStream(),args[0]);

但我总是得到响应:HTTP/1.1 401 Unauthorized 请给我任何建议?

4

2 回答 2

1

我以这种方式解决了身份验证问题:

protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException {
try { 
rResponse.setContentType("text/html");          
        URL url = new URL(
                "https://xxx/activities/service/atom2/todos");
        URLConnection con = url.openConnection();
        con.setConnectTimeout(150000);
        con.setReadTimeout(150000);
        writeCookies(con, rRequest);                        

        DO_SOMETHING (con.getInputStream());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}       


private String doesLTPATokenCookieExists(RenderRequest request) {
Cookie[] cookie = request.getCookies();
for (int i = 0; i < cookie.length; i++) {
    System.out.println("Cookie Name " + cookie[i].getName());
    if (cookie[i].getName().equals("LtpaToken"))
        return cookie[i].getValue();
}
return null;
}

public URLConnection writeCookies(URLConnection urlConn,
    RenderRequest request) {
String cookieString = "";
cookieString += "LtpaToken" + "=" + doesLTPATokenCookieExists(request) + "; ";
urlConn.setRequestProperty("Cookie", cookieString);     
return urlConn;
}
于 2011-05-04T14:55:49.247 回答
0

你没有提到你是如何进行身份验证的,这是至关重要的。正如 401 错误所暗示的那样,Connections 并未将您的请求视为经过身份验证。您需要一个有效的Authenticator实例,但您的代码片段表明您还没有做到这一点,对吗?

(顺便说一句,在使用 Lotus Connections API 时推荐使用Apache Abdera项目)。

于 2011-01-28T18:01:20.530 回答