Tuesday 15 September 2015

c# - Can't capture traffic with FiddlerCore with mobile user-agent in a Windows service -



c# - Can't capture traffic with FiddlerCore with mobile user-agent in a Windows service -

i have .net windows service using fiddler core capture content set of web sites. start net explorer process.start("iexplore.exe", url) works. problem need compare contents of desktop surfing , mobile surfing. have tried alter user agent of net explorer without success. next thought using chrome user-agent switcher simulate mobile surfing. problem can't fiddler core capture info chrome using service (regardless of user-agent switcher). works fine console application service captures nothing. i'm assuming shouldn't "session 0 isolation" problem fiddler , chrome running in same session (the session of service user). version of fiddlercore 4.4.0.1.

here code capturing data:

public class trafficevent { public string url { get; set; } public string contenttype { get; set; } public byte[] info { get; set; } } private list<trafficevent> trafficevents; private fiddler.sessionstatehandler responsehandler; private void handlebeforeresponse(fiddler.session session) { trafficevents.add(new trafficevent { url = session.fullurl, contenttype = session.oresponse.headers.exists("content-type") ? session.oresponse.headers["content-type"] : "", info = session.responsebodybytes }); } public void startfiddler() { trafficevents = new list<trafficevent>(); responsehandler = new fiddler.sessionstatehandler(handlebeforeresponse); fiddler.fiddlerapplication.beforeresponse += responsehandler; fiddler.wininetcache.clearfiles(); fiddler.config.ignoreservercerterrors = false; int port = 8888; fiddler.urlmoninterop.setproxyinprocess("127.0.0.1:" + port.tostring(), "<-loopback>"); fiddler.fiddlerapplication.startup(port, true, false); } public list<trafficevent> stopfiddler() { fiddler.fiddlerapplication.beforeresponse -= responsehandler; fiddler.fiddlerapplication.shutdown(); homecoming trafficevents; } public async task capturedata(string url) { startfiddler(); var proc = process.start("chrome.exe", url); proc.enableraisingevents = true; await task.delay(30 * 1000); proc.kill(); list<trafficevent> trafficevents = stopfiddler(); foreach (trafficevent trafficevent in trafficevents) { // store event in database } }

edit: not comment reply of ericlaw.

@ericlaw unfortunatelly proxy switch chrome did not work service. before have tried set proxy in config-file:

<!-- next section forcefulness utilize of fiddler applications, including running in service accounts --> <system.net> <defaultproxy> <proxy autodetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" /> </defaultproxy> </system.net>

that did not work either. changing user-agent via fiddler worked windows.forms.webcontrol not net explorer or chrome. running service application, not optimal working now. seek ua pick, thanks.

solution initial problem not beeing able capture info mobiles. reallye did not matter whether chrome or net explorer. reply of @ericlaw used ua-pick in ie, works capturing mobile sites in service!

firstly, maintain in mind can alter user-agent header sent using fiddler itself. alternatively, can utilize ua pick add-on.

if want maintain going chrome route, problem you're encountering service account isn't guaranteed check active user account proxy settings, fiddler registers proxy default.

the simplest approach start chrome command line points @ proxy server, e.g. chrome.exe --proxy-server=127.0.0.1:8888

c# google-chrome windows-services fiddler fiddlercore

No comments:

Post a Comment