asp.net mvc - How to make HttpClient relay traffic show up in Fidder or Charles? -
i have simple web api project based on example: http://aspnet.codeplex.com/sourcecontrol/latest#samples/webapi/relaysample/program.cs
however, in above sample relay working local server, in project relay working external web server real address; companyx.com
i using relay service (or, web proxy service) through browser, example, in browser request relayservice.com/companyx. relay service responds data external companyx.com site.
the relay works great, headers not correct , need see httpclient sending remote companyx.com server.
in fiddler or charles, request/response browser relayservice.com listed, request/response httpclient relayservice.com never shows up.
the relayservice.com running locally on machine, in iis7, i'm using hosts file direct traffic relayservice.com.
i have tried several variation of following when creating httpclient:
var clienthandler = new httpclienthandler { cookiecontainer = cookies, usecookies = true, usedefaultcredentials = false, proxy = new webproxy("http://localhost:8888"), useproxy = true, automaticdecompression = decompressionmethods.gzip, allowautoredirect = false, clientcertificateoptions = clientcertificateoption.automatic }; httpclient client = new httpclient(clienthandler);
update
if change useproxy = false
service continues work, when fiddler open or closed.
with useproxy = true
service fail, if fiddler open, following error:
object reference not set instance of object. @ system.domainnamehelper.idnequivalent(string hostname) @ system.net.httpwebrequest.getsafehostandport(uri sourceuri, boolean adddefaultport, boolean forcepunycode) @ system.net.httpwebrequest.generateproxyrequestline(int32 headerssize) @ system.net.httpwebrequest.serializeheaders() @ system.net.httpwebrequest.endsubmitrequest() @ system.net.connection.completeconnection(boolean async, httpwebrequest request)
with useproxy = true
, fiddler closed, following (obvious) error:
no connection made because target machine actively refused 127.0.0.1:8888
in same solution using httpwebrequest download data web , show in fiddler, seems issue httpclient.getasync()
i have tried on 2 machines identical results.
i have been struggling day, appreciated.
just recap: * relayservice.com running locally on machine, in iis7
hosts file has "127.0.0.1 relayservice.com"
relayservice.com mvc web api site uses httpclient.getasync() download content live web
fiddler/charles running locally on same machine
browser traffic local relayservice.com appears in fiddler/charles
httpclient.getasync() live web traffic not appear in fiddler/charles
fiddler/charles both date versions.
thanks again
you don't need in hosts file if you're using fiddler; can use fiddler's tools > hosts redirect traffic anywhere you'd like.
when trying capture traffic service account (e.g. asp.net acccount) typically want configure account use proxy; see http://fiddler2.com/blog/blog/2013/01/08/capturing-traffic-from-.net-services-with-fiddler details on that. if that, shouldn't need configure proxy object directly in code.
the exception you've shown suggests here's bug in generateproxyrequestline function. there change if update this: new webproxy("http://localhost:8888");
new webproxy("127.0.0.1", 8888);
?
generally speaking, .net applications bypass proxy urls pointed @ //localhost or //127.0.0.1, when debugging fiddler it's common use service url of //localhost.fiddler traffic sent proxy.
Comments
Post a Comment