我想使用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);
}
});
Result from inspecting the element
我正在尝试使用iframe,但未在iframe中呈现页面。有什么不对?如何根据iframe的页面请求发送凭据?
编辑:在这段代码中,我试图自动发送凭据,以便不显示身份验证提示。
使用基本身份验证,您需要呈现<iframe src="..."></iframe>
,浏览器将显示一个对话框以输入凭据。
[如果您在服务器上构造主体(即使用Wicket代码),则不需要iframe,而需要div
。