在尝试下载文档时给了我liferay登录页面内容

时间:2019-01-18 14:58:24

标签: http liferay

嗨,我正在尝试使用getURl从外部应用程序下载liferay文档,但是每次获取所有文档时,我都会获得liferay登录页面内容

我已经尝试过get-file-as-stream json-rpc调用,但这也给了我空响应

 private static byte[] getFile1(final long groupId, final long folderId, final String title, final String hostname, final String username, final String password) throws ClientProtocolException, IOException {
    final DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        final String filename = URLEncoder.encode(title);

        final HttpHost targetHost = new HttpHost(hostname.trim());
        System.out.println(targetHost.getHostName());
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
        System.out.println(creds);
        final AuthScope authscope = new AuthScope(targetHost);
        httpclient.getCredentialsProvider().setCredentials(authscope, creds);

        final AuthCache authCache = new BasicAuthCache();
        final BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);

        final BasicHttpContext localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        final HttpGet httpget = new HttpGet(hostname+"/documents/" + groupId + "/" + folderId + "/" + filename);


        final HttpResponse response = httpclient.execute( httpget, localContext);

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            final org.apache.http.HttpEntity entity = response.getEntity();

            if (entity != null) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                entity.writeTo(baos);
                return baos.toByteArray();
            }
        }
        return null;
    } finally {
        httpclient.getConnectionManager().shutdown();
    }

}

请为此提供解决方案,如果有其他下载方法,请也建议

0 个答案:

没有答案