0

我想使用 Apache Wicket 实现微前端架构,但我无法让它工作。

add(new WebMarkupContainer("testFrame") {

        @Override
        protected void onComponentTag(ComponentTag tag) {
            checkComponentTag(tag, "iframe");

            super.onComponentTag(tag);
            //Won't work like this if you want to send credentials.
            //tag.put("src", "http://localhost:8089/httpBasicAuthenticated/url/page/");

        }

        @Override
        public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
            Response response = getRequestCycle().getResponse();

            final CredentialsProvider provider = new BasicCredentialsProvider();

            String username = "user";
            String password = "password";

            final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

            provider.setCredentials(AuthScope.ANY, credentials);

            final HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
            HttpResponse httpResponse = null;

            String body = "";
            try {
                httpResponse = client.execute(new 
                   HttpGet("http://localhost:8089/httpBasicAuthenticated/url/page/"));
                body = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8");
            } catch (final IOException e) {

                e.printStackTrace();
            }
            response.write(body);

        }

    });

检查元素的结果

我正在尝试使用 iframe,但它没有在 iframe 内呈现页面。有什么不对?我将如何通过 iframe 根据页面请求发送凭据?

编辑: 在这段代码中,我试图自动发送凭据,以便不显示身份验证提示。

4

1 回答 1

0

使用基本身份验证,您需要呈现<iframe src="..."></iframe>,浏览器将显示一个对话框以输入凭据。

如果您在服务器上构建主体(即在 Wicket 代码中),那么您不需要 iframe,而是需要一个div.

于 2020-04-02T06:41:48.623 回答