Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

.NET Maui, Android Emulator, Fiddler – watch only emulator traffic

0.00/5 (No votes)
13 Sep 2024CPOL6 min read 391  
.NET MAUI, REST APIs, Android and Fiddler: Insights on the use of Fiddler How to configure development environment to use fiddler to monitor only the traffic from your android emulator and use fiddler to develop a deeper understanding of the API’s you are using.

.NET MAUI, REST APIs, Android and Fiddler: Insights on the use of Fiddler

How to configure development environment to use fiddler to monitor only the traffic from your android emulator and use fiddler to develop a deeper understanding of the API’s you are using.

Fiddler a network traffic monitoring tool that comes in two versions: Classic (free and no longer supported) and Everywhere (paid, with more features) has become an everyday tool for my mobile development.  

Building a mobile app with .NET Maui and REST API’s, it has helped me bridge the gap on API documentation and provide a view in to how the app is actually using the API’s.

My mobile app uses OpenLibrary.org which is an open-source project offering a set of web APIs to access their extensive library of books and artifacts. While the OpenLibrary team provides solid documentation, it can be somewhat sparse. To bridge these gaps, I’ll demonstrate how to use Fiddler alongside a .NET MAUI app to better understand and integrate with these REST APIs.

The application in question is a .NET MAUI mobile app designed to run on both Android and iOS. To monitor the REST API calls while the app is running, you need to set up Fiddler correctly on your Android device or emulator. Fiddler provides excellent documentation for this setup, which you can find here1.  You will likely also want to configure fiddler to monitor the traffic from the web app hosted by the provider to help understand the API’s they are using and how they use them for a deeper understanding of what is available.

After following the basic fiddler instrutions above I made some additional configurations:

  • In my situation I needed to disable the cellular capability in the emulator, ensuring it emulates Wi-Fi access only, not cellular data.  The proxy that was configured was configured via the WiFi interface so you want the emulator to only use WiFi in order to capture traffic from the device.
  •  Windows 11 network LAN settings turn of automatic proxy detection.   I did this because when fiddler starts up windows saw the proxy service and some of my network connections stopped working, in particular visualstudio github copilot seemed to get caught up in the proxy. This also stopped fiddler from monitoring my laptop network traffic which is a desired side effect.
  • In fiddler additionally I set the filter to only monitor traffic from the emulator process.  And filtered out some routine network calls that were just noise.

The following instructions from Bing Copilot is what I used to configure fiddler for an Android emulator.  It’s almost identical to the link above from fiddler documentation along with some additional configurations I made:

    1. Install Fiddler Classic:
    2. Download and install Fiddler Classic from the official website.
  1. Configure Fiddler Classic:
    • Open Fiddler and go to Tools > Options > Connections.
    • Check the box for Allow remote computers to connect.
    • Note the port number (default is 8888).
    • Restart Fiddler to apply the changes.
  2. Find Your IP Address:
    • Hover over the Online indicator in the top right corner of Fiddler to see your IP address.
  3. Configure the Android Emulator:
    • Start your Android emulator from Visual Studio.
    • In the emulator, go to Settings > Wi-Fi.
    • Long press on the connected network (usually “Wired eth1”) and select Modify Network.
    • Enable Show advanced options.
    • Set Proxy to Manual.
    • Enter your IP address and the port number (8888).
    • Note: if you move around to different work locations your ip address will likely change and need to be updated here.
  4. Install Fiddler Root Certificate:
    • Open the emulator’s browser and navigate to http://ipv4.fiddler:8888/.
    • Download and install the Fiddler root certificate.
    • Follow the prompts to install the certificate in the system account.
  5. Turn Off Cellular Data
    • Open emulator settings, navigate to network & internet / internet / the click on the gear icon for the mobile provider.
    • Click the slider to turn off use this sim
    • I have had a time or two when for some odd reason I can’t turn the sim off.  In that case I turn mobile data off and then that forces traffic through wifi and the proxy.
  6. Turn off laptop LAN Settings automatically detect
    • navigate to control panel/ network and internet / click on Internet Options/ click on the connections tab / click the LAN settings button 
    • uncheck automatic detection.
  7. Set Filters in Fiddler
    • In fiddler click on the filters icon, I set the filters to remove some noise entries.  Note that you don’t have to actually turn on Catpure Traffic under the File menu to monitor traffic from your emulator at this point.   The proxy on the emulator forwards the information directly to fiddler and capturing traffic is not needed in that capture traffic would be looking at the network traffic on your laptop.  
    • You can also filter traffic to a particular process and you might find this helpful under certain circumstances.
    • For example: the web site openlibrary.org is where I am currently working.  Figuring out their API’s.  I usually have 25 or more tabs open in edge, fortunately when the tab is asleep the title of the tab does not show up in the drop down list.  And it’s easy to find the tab that I want to monitor traffic from.   I can then filter on that process and select File Capture traffic and now I have monitored traffic from the emulator and from the one website that I am interested in.
  8. Capture Traffic:
    • Now that I have the emulator setup to forward to fiddler and the filters set to watch traffic from the one browser tab I am interested.  I can start File/Capture Traffic and see what all is going on with my app and the website it’s interacting with.
    • Launch the app you want to test in the emulator.
  9. A couple of examples of using fiddler.
    1. OpenLibrary.org does not have a documented API to update the reading status of a book that is a person’s bookshelf.   You can set a book to want to read, reading, already read.   The mobile I am building I want to be able to do the same thing.   In order to figure out how to make API call’s into openlibrary.org to do this I executed the steps in the web browser on openlibrary.org and updated a book.
    2. Looking at the traffic you can pick out the multi part form post that sets the status on book.
    3. Then when writing your code to execute the same post you can look at what your app is actually sending and compare it to what works and make adjustments.  Here I ran my app found the post that is attempting to set the date a book was read.  click on that post in the right hand window there are several ways to look at the post.   I like the raw view.   
      • For example here is one of my first attempts at setting the data a book was read.  I was able to see that the code was using \u0002 for a double quote.  When ultimately I needed the json to look like:

         

        {“event_type”:2,”year”:2018,”month”:5,”day”:18,”event_id”:null}

      • POST https://openlibrary.org/works/OL20643179W/check-ins HTTP/1.1

        Content-Type: application/json; charset=utf-8

        Cookie: pd=; session=/people/mynextbook%2C2024-09-06T14%3A56%3A52%2C04338%248a8ba7b97c5c121f24604a0332e40cc1

        User-Agent: Dalvik/2.1.0 (Linux; U; Android 15; sdk_gphone64_x86_64 Build/AP31.240517.022)

        Host: openlibrary.org

        Connection: Keep-Alive

        Accept-Encoding: gzip

        Content-Length: 124

         

        “{\u0022event_type\u0022: 2, \u0022year\u0022: 2018, \u0022month\u0022: 5, \u0022day\u0022: 18, \u0022event_id\u0022: null}”

Hope this provides some insight on how to utilize fiddler to help fill in the gaps on web apps you are integrating with and how you can troubleshoot your own apps by tracking exactly what api’s are being called and what they look like.

 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)