How to capture C++ REST SDK ( Casablanca) traffic in Fiddler?

In my last article, we looked at how to capture libcurl traffic in Fiddler. Another equally popular http transport stack is the CPP REST SDK, a.k.a., Casablanca.

We’ve used Casablanca widely across Microsoft on Windows and Xbox. A challenge that many folks face while using casablanca is how to actually see the http calls in Fiddler.

There are two steps to it:

1. Set Fiddler up to decrypt HTTP traffic.

2. Set the winhttp proxy to point to fiddler instance

Set up Fiddler to decrypt https traffic

From the Fiddler title menu bar, click Tools -> Options

In the options window that pops up, click HTTPS tab and select “Decrypt https traffic” as shown in the image below.

Decrypt HTTPS Traffic In Fiddler

Decrypt HTTPS Traffic In Fiddler

Set the winhttp proxy to point to Fiddler instance

1. Open an elevated command prompt.

2. On Vista and higher, set the winhttp proxy to the fiddler instance

netsh winhttp set proxy “<-loopback>”

or, import the wininet proxy

netsh winhttp import proxy ie

3. Restart Fiddler

This is not strictly required, but I’ve empirically run into some situations where a restart was needed.

And viola, the casablanca http traffic now shows up in Fiddler.

Fiddler showing traffic from CPP REST SDK

Fiddler showing traffic from CPP REST SDK

Here’s the code snippet I’m using to send a http request via casablanca.

// Casablanca_Fiddler.cpp : Defines the entry point for the console application.

#include "stdafx.h"

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams

int main(int argc, char* argv[])
  auto fileStream = std::make_shared<ostream>();

  // Open stream to output file.
  pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
    *fileStream = outFile;

    // Create http_client to send the request.
    http_client client(U(""));

    // Build request URI and start the request.
    uri_builder builder(U("/s"));
    builder.append_query(U("q"), U("quantum"));
    return client.request(methods::GET, builder.to_string());

    // Handle response headers arriving.
    .then([=](http_response response)
    printf("Received response status code:%u\n", response.status_code());

    // Write response body into the file.
    return response.body().read_to_end(fileStream->streambuf());

    // Close the file stream.
    return fileStream->close();

  // Wait for all the outstanding I/O to complete and handle any exceptions
  catch (const std::exception &e)
    printf("Error exception:%s\n", e.what());

  return 0;

Resetting the winhttp proxy

It is recommended that after you’re done debugging, you reset the winhttp proxy. If you don’t do this, any app that uses winhttp in some capacity will not work unless Fiddler is open. You probably don’t want that.

To reset the winhttp proxy, just run the following command from an elevated command prompt:

netsh winhttp reset proxy

Happy Debugging 🙂