質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Q&A

解決済

1回答

3371閲覧

titanium web proxyでブラウザの通信をトレースしたい。

pikumin001

総合スコア132

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

0グッド

0クリップ

投稿2017/07/03 11:26

以下のことを試してみたのですが、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; } } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

以下の2行を削除してみてください。

proxyServer.UpStreamHttpProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 }; proxyServer.UpStreamHttpsProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };

UpStreamProxyはTitaniumがさらにプロキシを使う場合に使用します。
WebBrowser > Titanium > Web Server
WebBrowser > Titanium > UpStream Proxy > Web Server

投稿2017/07/06 11:22

hmmm

総合スコア818

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

pikumin001

2017/07/06 17:03

UpStreamHttpProxyを消去し、 proxyServer.SetAsSystemHttpProxy(explicitEndPoint); proxyServer.SetAsSystemHttpsProxy(explicitEndPoint); としたら無事に取得することが出来ましたが、 var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true){}; としたばあい、PCすべての通信がトレースされてしまうと思うのですが、 それを利用しているアプリのみに絞ることは不可能でしょうか?
pikumin001

2017/07/07 12:15

度々すみません。 教えていただいたページでアドレスとポートを設定する方法はわかったのですが、 肝心のtitanium web proxyのアドレスとポートがわかりませんでした。 どこかで設定と取得ができるとはおもうのですが、ご存じないでしょうか?
hmmm

2017/07/10 01:57 編集

redeme.mdのusageを見てください。proxyServer.AddEndPoint(explicitEndPoint);とありますよ。
pikumin001

2017/07/10 18:29

ありがとうございました、無事に設定することができました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問