question

Upvotes
Accepted
301 6 17 27

Debugging TRKD API based client app using Fidder

What is the best way to use Fiddler in debugging a client application that is based on a TRKD API?

rkd-apirkdfiddler
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

1 Answer

Upvotes
Accepted
791 9 7 14

Fiddler is an HTTP Proxy running on port 8888 (by default) on your local PC. You can configure any application which accepts a HTTP Proxy to run through Fiddler so you can debug its traffic. WinINET-based applications (E.g. Microsoft Office, Internet Explorer, etc) should automatically use Fiddler while it's running and the "Capture Traffic" box is checked on the Fiddler File menu.

.NET framework

While launched, Fiddler sets itself as the WinINET proxy server so if an application is configured to use the default proxy, Fiddler starts catching the traffic automatically. In case of WCF web-service client application, bindings are configured such way by default so ordinarily you won't need any additional actions for Fiddler to start catching requests and responses from a TRKD API application. In other cases or if you want to setup a proxy server in the code explicitly, you can use the approach described below. In order to start catch request / responses TRKD API add the following code to your .NET application (SSL connection supported):

...

WebProxy wproxy = new WebProxy("http://localhost:8888", true);

WebRequest.DefaultWebProxy = wproxy;

ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallback;

...

static bool CertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true;

}

It is also necessary to update the application configuration file (web.config or app.config) to use Fiddler as proxy server.

JAVA

Traffic in Java based application can be redirected to Fiddler with the following way:

jre -DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888 MyApp

Or in code:

• for http traffic:

System.setProperty("http.proxySet", "true");

System.setProperty("http.proxyHost", "localhost");

System.setProperty("http.proxyPort", "8888");

• for https traffic:

System.setProperty("https.proxySet", "true"); System.setProperty("https.proxyHost", "localhost");

System.setProperty("https.proxyPort", "8888");

Note: when capturing HTTPS traffic using Fiddler you may face with the following exception: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

In this case you need to import Fiddler certificate into local keystore.

To get Fiddler certificate please go to Fiddler Options -> HTTPS and click Export Root Certificate to Desktop button. Then use that same mechanism of adding of the certificate to keystore as described in the article How to import TRKD certificate into local Java keystore?

PHP

You can set up the Fiddler proxy in PHP code with PHP/CURL library. Add the following code to application in order to pass traffic through Fiddler:

curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');

Another way is to set the Fiddler proxy for a PHP SOAP client individually:

$client = new SoapClient($wsdl_url, array('soap_version' => SOAP_1_2, "proxy_host" => '127.0.0.1', "proxy_port" => 8888));

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea