问题
I have an ASP.NET WebForms app (sender) which sends a WebClient post request to another ASP.NET app (receiver) on the same dev machine. The WebClient post is initiated by clicking a button in the sender app. It's a test app and the form has only the button. I can see the post from the button in Fiddler but I don't see the post request from the WebClient method. Why?
I know the WebClient post runs successfully because the breakpoint is hit in the receiver app and the Forms collection has the value of the input field from the WebClient request from the sender app. (Using Windows 8.1)
Update This is the call:
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);
}
回答1:
.NET and IE(before version 9) are not sending requests to localhost through any proxies. There are 3 possible solutions:
- Use machine name or hostname:
http://<machine name>/testform/default.aspx
- Add
ipv4.fiddler
to the URL:http://localhost.fiddler/testform/default.aspx
- Add custom rule to the fiddler:
static function OnBeforeRequest(oSession:Fiddler.Session){
if (oSession.HostnameIs("MYAPP")) {
oSession.host = "<put your ip address and port here>";
}
}
Then you should be able to capture traffic through http://myapp/testform/default.aspx
Reference Problem: Traffic sent to http://localhost or http://127.0.0.1 is not captured.
回答2:
Could be multiple things. Here are some possibilities
- You have Fiddler set to filter to only show things from a particular process (or some other type of filter but process is the easiest one to accidentally turn on)
- You have not turned on HTTPS capture in Fiddler but this missing request is HTTPS (it's off by default)
- Your WebClient has a custom proxy configured and isn't pulling the default settings from IE
来源:https://stackoverflow.com/questions/25836655/cant-see-webclient-post-request-in-fiddler