2

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

4

1 回答 1

2

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.

于 2010-09-25T16:44:30.187 回答