以下のことを試してみたのですが、titanium web proxyのレスポンス、リクエストのイベントが呼び出されていないので
何かが間違っていると思うのですが、この手のものを使うのは初めてて調べても何も出てこないので困っております。
WindowsFormでボタンを3つ配置、WebBrowserを1つ配置。
ボタン1でサーバースタート。2で終了。3でブラウザをナビゲート。
別のクラスでボタン1が押された時にtitanium web proxyのサーバーポートを127.0.0.1:8888(もしくはlocalhost:8888)
にIEのプロキシを設定。
鯖スタート後にボタン3を押すと、
プロキシ サーバーは応答していません
プロキシ設定 localhost:8888を確かめてください。
LAN を使っている場合は、[LAN の設定] をクリックしてください。
と表示され、プロキシを設定しない場合はページを閲覧することは出来すが、プロキシサーバーを通していないため、
レスポンス、リクエストのイベントは呼び出されないといった状況です。
また、サーバーのポート設定しないでデフォルトのポートとアドレスをIEに設定してもだめでした。
(調べてみるとデフォルトは127.0.0.1:8080のようです)
using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Forms; using Titanium.Web.Proxy; public partial class test : Form { public test() { InitializeComponent(); } ProxyServer proxyServer; private void button1_Click(object sender, EventArgs e) { proxyServer = new ProxyServer(); proxyServer.BeforeRequest += OnRequest; proxyServer.BeforeResponse += OnResponse; proxyServer.UpStreamHttpProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 }; proxyServer.UpStreamHttpsProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 }; proxyServer.Start(); //IEのLAN設定のプロキシを以下に設定// SetProxy.SetConnectionProxy("localhost:8888"); } private void button2_Click(object sender, EventArgs e) { //サーバーをストップし、プロキシをデフォルトに戻す// proxyServer.Stop(); SetProxy.RestoreSystemProxy(); } private void button3_Click(object sender, EventArgs e) { webBrowser1.Navigate("https://www.google.co.jp/"); } private async Task OnResponse(object arg1, Titanium.Web.Proxy.EventArguments.SessionEventArgs e) { var responseHeaders = e.WebSession.Response.ResponseHeaders; //if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return; if (e.WebSession.Request.Method == "GET" || e.WebSession.Request.Method == "POST") { if (e.WebSession.Response.ResponseStatusCode == "200") { if (e.WebSession.Response.ContentType != null && e.WebSession.Response.ContentType.Trim().ToLower().Contains("text/html")) { byte[] bodyBytes = await e.GetResponseBody(); await e.SetResponseBody(bodyBytes); string body = await e.GetResponseBodyAsString(); await e.SetResponseBodyString(body); } } } } private IDictionary<Guid, string> requestBodyHistory; public async Task OnRequest(object sender, Titanium.Web.Proxy.EventArguments.SessionEventArgs e) { Console.WriteLine(e.WebSession.Request.Url); var requestHeaders = e.WebSession.Request.RequestHeaders; var method = e.WebSession.Request.Method.ToUpper(); if ((method == "POST" || method == "PUT" || method == "PATCH")) { //Get/Set request body bytes byte[] bodyBytes = await e.GetRequestBody(); await e.SetRequestBody(bodyBytes); //Get/Set request body as string string bodyString = await e.GetRequestBodyAsString(); await e.SetRequestBodyString(bodyString); //store request Body/request headers etc with request Id as key //so that you can find it from response handler using request Id requestBodyHistory[e.Id] = bodyString; } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/06 17:03
2017/07/07 00:30
2017/07/07 12:15
2017/07/10 01:57 編集
2017/07/10 18:29