05.
using
Fiddler;
06.
public
partial
class
App : Application
07.
{
08.
protected
override
void
OnStartup(StartupEventArgs e)
09.
{
10.
//Setup internal proxy
11.
FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;
12.
oFCSF = (oFCSF & ~FiddlerCoreStartupFlags.RegisterAsSystemProxy);
13.
FiddlerApplication.Startup(0, oFCSF);
14.
base
.OnStartup(e);
15.
}
16.
protected
override
void
OnExit(ExitEventArgs e)
17.
{
18.
FiddlerApplication.Shutdown();
19.
base
.OnExit(e);
20.
}
21.
}
22.
23.
//MainWindow.xaml.cs
24.
using
Fiddler;
25.
using
Awesomium.Core;
26.
using
Awesomium.Windows.Controls;
27.
using
System.Collections.Concurrent;
28.
29.
public
partial
class
MainWindow : Window
30.
{
31.
WebControl AweWebControl;
32.
ConcurrentQueue<
string
> CQFiddlerPayloads;
33.
public
MainWindow()
34.
{
35.
CQFiddlerPayloads =
new
ConcurrentQueue<
string
>();
36.
37.
FiddlerApplication.OnWebSocketMessage += FiddlerApplication_OnWebSocketMessage;
38.
FiddlerApplication.Log.OnLogString += Log_OnLogString;
39.
40.
WebCore.Initialize(
new
WebConfig
41.
{
42.
UserAgent =
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
43.
});
44.
WebPreferences prefs =
new
WebPreferences()
45.
{
46.
ProxyConfig =
"http://127.0.0.1:"
+ FiddlerApplication.oProxy.ListenPort.ToString(),
47.
};
48.
WebSession webSession = WebCore.CreateWebSession(prefs);
49.
AweWebControl =
new
WebControl();
50.
AweWebControl.WebSession = webSession;
51.
AweWebControl.CertificateError += AweWebControl_CertificateError;
52.
53.
InitializeComponent();
54.
55.
GridAweBrowser.Children.Add(AweWebControl);
57.
58.
//create DispatcherTimer to process CQFiddlerPayloads
59.
}
60.
61.
string
LogString =
""
;
62.
void
Log_OnLogString(
object
sender, LogEventArgs e)
63.
{
64.
LogString += e.LogString +
"\n"
;
65.
// /Fiddler.CertMaker> Using Fiddler.DefaultCertificateProvider+MakeCertEngine for certificate generation
66.
// [WebSocket #20] Read from Server failed... Object reference not set to an instance of an object. <<not always!
67.
// [WebSocket #20] Read from Client returned error: 0
68.
// [WebSocket #20] Read from Server returned error: 0
69.
}
70.
71.
void
FiddlerApplication_OnWebSocketMessage(
object
sender, WebSocketMessageEventArgs e)
72.
{
73.
if
(e.oWSM.FrameType == WebSocketFrameTypes.Text && e.oWSM.IsFinalFrame ==
true
)
74.
CQFiddlerPayloads.Enqueue(e.oWSM.PayloadAsString());
75.
}
76.
77.
void
AweWebControl_CertificateError(
object
sender, CertificateErrorEventArgs e)
78.
{
79.
e.Handled = EventHandling.Modal;
80.
e.Ignore =
true
;
81.
}
82.
}