Java中获取HTTP流的内容+ Mozilla XPCOM
我经常阅读 StackOverflow 作为获取答案的来源;但现在我有一个非常具体的问题,我在互联网上找不到任何数据。我相信您会一如既往地提供帮助! :D
基本上,我依靠 Mozilla 的 XULRunner 及其 XPCOM 对象来分析 Linux 上 Java 应用程序中 SWT 浏览器的 HTTP 流。
很大程度上基于 Java SWT 网站上的 Snippet128 和 Snippet321(抱歉,无法发布超过 1 个 URL :/ ),到目前为止,我的浏览器可以使用 nsIHttpHeaderVisitor 解析所有 HTTP 标头 - 并执行一些漂亮的操作,例如将它们打印在树之类的。
完整源代码位于此处。
现在……已经很好了。它涵盖了我想做的大部分事情(首先是学校作业,比要求的更进一步!)。
但我真正想要的是能够从每个 HTTP 请求中获取原始“内容”数据:当然是 HTML;还有 CSS 和图像。
我一直在尝试不同的方法来实现这一目标,但到目前为止一切都失败了:
使用 XPCOM 对象 - 哪一个?
- nsIInputStream 会是一个不错的选择。但我似乎找不到好的流实际上在哪里...... nsIHttpChannel open() 方法(返回 nsIInputStream)似乎是由 SWT 浏览器调用的,让我无法取回流。
- nsIRequest:运气不好。
- 另一个我可能错过的听众?我刚刚花了一个小时尝试使用 nsIHttpActivityObserver 接口,但它没有给我任何 HTTP 内容(只有 GET 和 200 OK)。
使用另一个对象
- 例如,SWT 的浏览器。嗯,它有点有效:它的 getText() 方法为我提供了我正在访问的页面的 html 源代码。但我想要更多!
我真的被困在这里,我将非常感谢任何帮助。
干杯!
弗洛朗
I've often read StackOverflow as a source to get answers; but now I have a very specific question and I can't really find any data on the internet. I trust you to be as helpful as always! :D
Basically, I'm relying on Mozilla's XULRunner and its XPCOM objects to analyze the HTTP stream of an SWT browser in a Java application on Linux.
Heavily based on Snippet128 and Snippet321 from the Java SWT website (can't post more than 1 URL sorry :/ ), my browser so far can parse all of the HTTP headers using an nsIHttpHeaderVisitor - and do some pretty stuff like printing them on a tree and such.
Full source is here.
Now... That's already pretty good. It covers the majority of what I want to do (school assignment at first, going a bit further than asked!).
But what I would really like is to be able to get the raw "content" data from every HTTP request: HTML of course ; but also CSS and images.
I've been trying different ways to achieve this goal, but everything failed so far:
Using an XPCOM object - which one?
- nsIInputStream would be a good one. But I can't seem to find where the good stream actually is... The nsIHttpChannel open() method (who gives back an nsIInputStream) seems to be called by the SWT browser, leaving me with no way of getting the stream back.
- nsIRequest : no luck.
- another Listener that I'd have missed? I just spent an hour trying to use the nsIHttpActivityObserver interface, but it doesn't give me any HTTP content (merely GETs and 200 OK).
Using another object
- the SWT's browser for instance. Well it kinda works: its getText() method gives me the html source of the page I'm visiting. But I want more!
I'm really stuck here, and I would greatly appreciate any help.
Cheers!
Florent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许 nsITraceableChannel 可以帮助你?
Perhaps nsITraceableChannel can help you?