c# - HttpClient does not work with Fiddler -
i have gone through forum , tried techniques still fiddler not able capture traffic. help.
following works fiddler, webapi server working. c# client returns ok.
http://localhost:49305/api/employee/12345
.
host file
#localhost name resolution handled within dns itself. #127.0.0.1 localhost #::1 localhost
.
static async task goany() { httpclienthandler clnthand = new httpclienthandler() { cookiecontainer = new cookiecontainer(), proxy = new webproxy("http://localhost:8888", false), useproxy = true, usedefaultcredentials = false }; httpclient clnt = new httpclient(clnthand) { baseaddress = new uri("http://localhost:49305") }; clnt.defaultrequestheaders.accept.clear(); clnt.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); httpresponsemessage resp = await clnt.getasync("api/employee/12345"); if (resp.statuscode == system.net.httpstatuscode.ok) { string c = resp.content.tostring(); } }
this known issue when using localhost.
your url http://localhost:49305
, need change include .fiddler
after localhost: http://localhost.fiddler:49305
.
once have done this, request httpclient should appear in fiddler.
please see question: how can trace httpclient request using fiddler or other tool?
Comments
Post a Comment