c# - 使用 C# win 应用程序打开 Web 浏览器并在请求中添加请求 header

标签 c# winforms webclient

我有一种情况,我想模拟一个到达应用程序的 Web 请求。它包含一些 url 值和请求 header 。

我知道我可以使用

启动浏览器
var url = "http://test.com";
var sInfo = new ProcessStartInfo(url);
Process.Start(sInfo);

但是我想在我想在浏览器中打开的 url 中添加一些 header 值。 我曾尝试使用不同的东西,但无法在浏览器中打开它。

我使用了 WebClient 如下

WebClient client = new WebClient();
var url = "http://test.com";
client.Headers.Add("USER", "ABC");
string text=client.DownloadString(url);

但是我不知道如何在网络浏览器中使用这个字符串。

我也尝试过 WebBrowser 但无法模拟。

最佳答案

这没有标准。如果你想传递自定义 header ,你需要咨询你正在使用的网络浏览器。不过,我认为任何主流浏览器都没有这样的功能 - 但是,Chrome 和 Firefox 都有扩展,允许您全局向每个请求添加 header 。也许这对您来说已经足够了,也许还不够。

关于c# - 使用 C# win 应用程序打开 Web 浏览器并在请求中添加请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32308254/

相关文章:

c# - 30 秒无用户交互后引发事件

c# - 使用c#将图像插入到xml文件中

c# winforms均匀分布3个控件

java - 如何使用httpunit获取json页面

c# - "A connection attempt failed because the connected party did not properly respond after a period of time"使用 WebClient

c# - C# 中的可空类型

c# - "TLS session of data connection has not resumed or the session does not match the control connection"错误

c# - 多列组合框或 DataGridCombo Box 列收缩

c# - 向方法中添加事件

javascript - Parse SDK for javascript 如何发送 ping 到解析服务器以验证 Web 客户端和服务器之间的连接