使用 HtmlUnit 读取所有响应标头
我试图使用 http 单元读取我的应用程序的响应标头 -
WebClient webClient = new WebClient();
WebClient.setThrowExceptionOnScriptError(false);
HtmlPage currentPage = webClient.getPage("http://myapp.com");
WebResponse response = currentPage.getWebResponse();
System.out.println(response.getResponseHeaders());
我确实看到了响应标头,但它们仅限于第一个 http get 请求。 当我使用 LiveHTTPHeaders 插件作为 firefox 插件时,我得到了所有 get 请求和相应的标头响应。
有没有什么方法可以获取所有后续请求的 http 标头,而不仅仅限于第一次获取?
I was trying to use http unit to read response header for my application -
WebClient webClient = new WebClient();
WebClient.setThrowExceptionOnScriptError(false);
HtmlPage currentPage = webClient.getPage("http://myapp.com");
WebResponse response = currentPage.getWebResponse();
System.out.println(response.getResponseHeaders());
I do get to see the response headers but they are limited to only first http get request.
When I used LiveHTTPHeaders plugin for firefox plugin I got to all the get requests and corresponding header responses.
Is there any way to get http header for all subsequent requests and not being limited to just first get?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说效果很好。
works fine for me.
下面是一个简洁的示例,显示了 HTMLUnit 响应中的所有标头:
Here is a concise example displaying all the headers from a response with HTMLUnit:
AFAIK,这应该有效:
这段代码有效吗?如果是这样,那么您可能没有正确分配 currentPage 变量,因此它保留原始值。
AFAIK, this should work:
Does this code work? If it does, then you are probably not properly assigning the currentPage variable so it keeps holding the original values.