在 System.Windows.Forms.WebBrowser 中添加 HTTP 标头和发布数据

发布于 2024-09-24 14:17:51 字数 97 浏览 2 评论 0原文

我正在尝试使用 System.Windows.Forms.WebBrowser 发出发送 POST 数据和自定义 HTTP 标头的请求。我也想设置请求的用户代理。我怎么能这样做呢?

I'm trying to use the System.Windows.Forms.WebBrowser to make a request that both sends POST data and custom HTTP headers. I'd like to set the user-agent of the request as well. How could I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-10-01 14:17:51

您可以使用此 Navigate 重载发送 POST 数据和其他 HTTP 标头。但是,要完全控制请求表单(包括用户代理)并抑制 IE 默认发送的标头(如果可能的话),需要大量的互操作,因此您最好使用 HttpWebRequest 滚动自己的请求并将输出输入浏览器以某种方式。

以下是有关自定义 Web 浏览器。请注意,这是基于 .NET WebBrowser 控件的 COM 基础。对于除最常见场景之外的所有场景,您都需要浏览控件的 IWebBrowser2 接口,这意味着熟悉 COM 互操作。这并不完全有趣,但也没有那么糟糕。

You can send POST data and additional HTTP headers using this Navigate overload. But to have complete control over the request form including user agent and suppressing headers that IE will send by default would (if even possible) require so much interop that you'd be better off just rolling your own requests using HttpWebRequest and feeding the output into the browser somehow.

Here is some additional information on customizing the WebBrowser. Note that this is based on the COM underpinnings of the .NET WebBrowser control. For all but the most common scenarios you need to go through the control's IWebBrowser2 interface which means getting familiar with COM interop. It's not exactly fun, but it's not that bad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文