.NET WebClient post request not appearing in Fiddler

8 posts, 0 answers
  1. Tony
    Tony avatar
    18 posts
    Member since:
    Sep 2014

    Posted 14 Sep 2014 Link to this post

    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)

    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);
    }
  2. Tony
    Tony avatar
    18 posts
    Member since:
    Sep 2014

    Posted 14 Sep 2014 in reply to Tony Link to this post

    I am not using any filters
  3. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 15 Sep 2014 Link to this post

    1. Traffic from applications running in different user accounts (e.g. the ASP.NET service account) isn't automatically captured by Fiddler running in the logon user's account. See http://blogs.telerik.com/fiddler/posts/13-01-08/capturing-traffic-from-.net-services-with-fiddler for details.

    2. The .NET Framework is hardcoded to bypass proxies when making requests to "localhost." The workaround is to use the machine name, or "localhost.fiddler" instead. 

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  4. Tony
    Tony avatar
    18 posts
    Member since:
    Sep 2014

    Posted 16 Sep 2014 in reply to Eric Lawrence Link to this post

    It's still not working. I made the changes to the two v4. mahine.config files. When I use 'localhost.fiddler' in the WebClient url, I get this error "The remote name could not be resolved: 'localhost.fiddler". When I use the machine name, I don't get any errors but the request is not in Fiddler. If I use 'localhost.fiddler' in the browser to bring up the page, the page comes up. I don't why when it's used in WebClient, WebClient can't resolve it while the browser can.
  5. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 16 Sep 2014 Link to this post

    Howdy, Tony--

    Fear not-- thousands of people use Fiddler to capture WebClient traffic every day, so we'll get this working.

    If using "localhost.fiddler" results in a DNS failure, that means that your client is not using the proper proxy settings. I assume that you've confirmed that your application is using .NET4 and not an earlier version? Do you have any web.config or app.config files that may be overriding the default machine.config proxy settings?

    If you're debugging locally, you can also temporarily debug by simply assigning the WebClient's Proxy property directly.

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Tony
    Tony avatar
    18 posts
    Member since:
    Sep 2014

    Posted 17 Sep 2014 in reply to Eric Lawrence Link to this post

    I am using 4.5 on a new empty WebForms app. There's nothing added to web.config. I modified the code now so that WebClient uses a proxy.   WebProxy proxy = new WebProxy();
                    proxy.Address = new Uri("http://127.0.0.1:8888");
                    client.Proxy = proxy;
                    ......

    Now I see the WebClient post in Fiddler but the final result is this error:  The remote server returned an error: (502) Bad Gateway. I get the same result with or without the machine.config changes.
  7. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 17 Sep 2014 Link to this post

    Hi, Tony--

    I'm afraid that I don't know what "the final result is this error" means.

    Where do you see that error, and what exactly do you see in Fiddler? If the URL is HTTPS, have you configured Windows to trust the Fiddler Root certificate on a machine-wide basis?

    1. In Fiddler’s Tools > Fiddler Options > HTTPS tab, click Export Root Certificate to Desktop.

    2. Launch mmc.exe.

    3. Click File > Add/Remove Snap-In.

    4. Select the Certificates snap-in and press Add.

    5. When prompted This snap-in will always manage certificates for: choose Computer Account

    6. Click Local Computer, then Finish, then OK.

    7. Open the Certificates (Local Computer) node.

    8. Right-click the Trusted Root Certificate Authorities folder and choose All Tasks > Import.

    9. Choose the file you exported in step #1 and import it.



    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Tony
    Tony avatar
    18 posts
    Member since:
    Sep 2014

    Posted 18 Sep 2014 in reply to Eric Lawrence Link to this post

    "The remote server returned an error: (502) Bad Gateway" is what shows in the browser after I click the button. 

    I got it working now. It didn't work if localhost or 127.0.0.1 or the machine name were used in WebClient. ipv4.fiddler or localhost.fiddler worked. Thanks for your help.
Back to Top