使用 WebBrowser 控件发送自定义信息
我有以下问题: 我需要在 WebBrowser 控件发出的每个请求中发送一些自定义信息。例如,信息之一是使用的应用程序版本。
现在我已经在这里读到不可能为 WebBrowser 控件设置自定义标头。
我已经尝试拦截所有请求并使用 WebClient(或 HttpWebRequest)自行执行它们。它可以部分工作,但有很多错误并且经常抛出错误。
还有其他想法如何通过 WebBrowser 控件发出的每个请求发送自定义信息吗?
i have the following problem:
i need to send some custom info with every request made by a WebBrowser control. For example one of the infos is the used app version.
Now i have already read here that it is impossible to set custom headers for a WebBrowser control.
I have already tried to intercept all requests and perform them on my own with a WebClient (or HttpWebRequest). It partially works but is very buggy and often throws errors.
Any other ideas how to send the custom infos with every request that is made by the WebBrowser control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在与之交互的网络服务器是您自己的吗?您可以为您想要的所有数据添加一个查询字符串参数吗?然后
你就可以在服务器上处理它,无论是在 aspx 页面中的请求期间,还是通过 Web 服务器的日志文件。
Is the web server you are interacting with your own? Could you just add a query string parameter for all the data you want? Something like
Then you'd be able to process it on the server, either during that request in the aspx page, or via the logfiles for the web server.
我怀疑,由于您无法修改直接从 WebBrowser 发送的内容,并且拦截每个调用并充当每个请求的代理,同时仍然维护所有浏览器功能可能太麻烦了。
相反,我建议发送一个附加请求,其中仅包含您每次提出请求时想要记录的附加信息。
这可能会导致大量开销,因此可能会更容易发送一次,然后在第一个请求上将其哈希值或其他一些标识密钥传递给网页(作为查询字符串参数),以便它可以协调这两个部分的信息。假设您控制着 Web 服务器,那么您可以让 Web 服务器将该哈希值/密钥设置为 Cookie,以便将其与来自控件的后续请求一起再次传递。
I suspect that as you can't modify the content that gets sent directly from the WebBrowser and that intercepting every call and acting as a proxy for every request, while still maintaining all browser functionality may be too cumbersome.
Instead I'd suggest sending an additional request with just the additional information you want to record every time you make a request.
That could lead to a lot of overhead so it might be easier to send this once and then pass a hash of it, or some other identifying key to the webpage (as a querystring parameter) on the first request so it can reconcile the 2 pieces of information. Assuming that you are in control of the web server you could then have the web server set that hash/key as a cookie so it would be passed again with subsequent request from the control.