我有一个 ASP.NET WebForms 应用程序(发送方),它将 WebClient post 请求发送到同一开发计算机上的另一个 ASP.NET 应用程序(接收方)。 WebClient 帖子是通过单击发件人应用程序中的按钮启动的。这是一个测试应用程序,表单只有按钮。我可以从 Fiddler 中的按钮看到帖子,但看不到来自 WebClient 方法的帖子请求。 为什么?
我知道 WebClient 帖子成功运行,因为在接收方应用程序中命中了断点,并且 Forms 集合具有来自发送方应用程序的 WebClient 请求的输入字段的值。 (使用Windows 8.1)
更新这是通话:
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
var data = "FirstName=John";
var result = client.UploadString("http://localhost/testform/default.aspx", "POST", data);
Console.WriteLine(result);
}
最佳答案
.NET 和 IE(版本 9 之前)不会通过任何代理向本地主机发送请求。有 3 种可能的解决方案:
- 使用计算机名称或主机名:
http://<machine name>/testform/default.aspx
- 添加
ipv4.fiddler
到网址:http://localhost.fiddler/testform/default.aspx
- 向 fiddler 添加自定义规则:
static function OnBeforeRequest(oSession:Fiddler.Session){
if (oSession.HostnameIs("MYAPP")) {
oSession.host = "<put your ip address and port here>";
}
}
那么你应该能够通过 http://myapp/testform/default.aspx
捕获流量
引用 Problem: Traffic sent to http://localhost or http://127.0.0.1 is not captured
.
关于asp.net - 在 Fiddler 中看不到 WebClient post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25836655/