艦これのバトルJSONを再解析(祥鳳改小破編) | Moonmile Solutions Blog
http://www.moonmile.net/blog/archives/5517
の続きで、ブラウザの通信をトラップするのに InternetSetOption を使っていたのですが、URLMonInterop.SetProxyInProcess を使ってもできるよ、という話があったので試しに。InternetSetOption 関数自体は結構古くからある方法で定番のようです。たぶん、内部的にも同じことをやっているのかなと。
1 2 3 4 5 6 7 8 | private void Window_Loaded( object sender, RoutedEventArgs e) { FiddlerApplication.Startup(PROXY_PORT, false , true ); // SetIESettings("localhost:" + PROXY_PORT); URLMonInterop.SetProxyInProcess( "127.0.0.1:" + PROXY_PORT.ToString(), "" ); FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete; this .wb.Navigate(URL_LOGIN); } |
こんな感じで1行で済みます。ちなみに InternetSetOption 関数を使った場合はこんな感じ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | internal struct INTERNET_PROXY_INFO { public int dwAccessType; public IntPtr proxy; public IntPtr proxyBypass; } [DllImport( "wininet.dll" , SetLastError = true )] public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength); private void SetIESettings( string proxyUri) { const int INTERNET_OPTION_PROXY = 38; const int INTERNET_OPEN_TYPE_PROXY = 3; INTERNET_PROXY_INFO proxyInfo; proxyInfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY; proxyInfo.proxy = Marshal.StringToHGlobalAnsi(proxyUri); proxyInfo.proxyBypass = Marshal.StringToHGlobalAnsi( "local" ); var proxyInfoSize = Marshal.SizeOf(proxyInfo); var proxyInfoPtr = Marshal.AllocCoTaskMem(proxyInfoSize); Marshal.StructureToPtr(proxyInfo, proxyInfoPtr, true ); InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, proxyInfoPtr, proxyInfoSize); } |
サンプルはこんな感じ
https://github.com/moonmile/KcAgent/tree/master/KcAgentBrowser
F12キーを押すとデバッグ用のウィンドウを開きます。そのうち、JSON 解析と swf/mp3 のダウンロード機能とかつける予定。