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

Adding HTTP Headers and Post data in a System.Windows.Forms.WebBrowser(在 System.Windows.Forms.WebBrowser 中添加 HTTP 标头和发布数据)

本文介绍了在 System.Windows.Forms.WebBrowser 中添加 HTTP 标头和发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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?

推荐答案

您可以使用此 导航重载.但是要完全控制包括用户代理在内的请求表单并抑制 IE 默认发送的标头(如果可能的话)需要如此多的互操作,因此最好使用 HttpWebRequest 滚动自己的请求并将输出输入浏览器不知何故.

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.

这里是关于自定义网络浏览器.请注意,这是基于 .NET WebBrowser 控件的 COM 基础.除了最常见的场景,您需要通过控件的 IWebBrowser2 接口,这意味着熟悉 COM 互操作.这不是很有趣,但也没有那么糟糕.

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.

这篇关于在 System.Windows.Forms.WebBrowser 中添加 HTTP 标头和发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 System.Windows.Forms.WebBrowser 中添加 HTTP 标头和发布数据

基础教程推荐