Share via


Setting up Fiddler to capture network traffic from the Unity 3D Editor

Our support team over at Microsoft is really getting into cross platform development.  Originally I set out to show how to set up Fiddler to capture network traffic on iOS, Android, and Windows devices, but it turns out that is well documented here.  The fiddler docs do a good job of covering almost all platforms and Operating Systems..  However, one day I was working with a leaderboard hosted in Azure Mobile Services and trying to connect my Unity game to it.  I noticed Fiddler was not capturing the network traffic when I was running the code from the Unity editor.  So I decided to figure out how to do that and will share the details with everyone in this post.

 

Setting up Fiddler

If you are running Unity on Windows then you can set up fiddler on the same Windows machine.  If you are running Unity on MAC you will need another system to run fiddler on that is on the same network as the MAC.  For example another Windows machine,  or an instance of Windows running on Parallels.  Either way you need a separate operating system to run Fiddler on.   On the machine running Fiddler perform the following steps to set up Fiddler:

  1. Install Fiddler and choose the ‘Built for .NET 4 ‘ version

  2. Run Fiddler and choose (from the menu) Tools, Fiddler Options…  Check these boxes in the HTTPS tab of the resulting dialog (and hit OK): 

    image

  3. Set these options in the Connections tab and then hit OK:

    Fiddler options for connections

  4. Save the Fiddler options

  5. Note the IP Address and port of the proxy in the upper right corner of Fiddler by moving the mouse over the Online icon:

    Fiddlers proxy address

  6. Test the iPv4 address listed.  If you have more than one IP Address like I do first ignore the iPv6 options and test the iPv4 options one by one.  To test browse to https://ipaddress:8888, and you should see Fiddlers default HTTP response:

    Fiddler default HTTP response

In this example the proxy configuration Uri will be “https://172.16.0.6:8888”.  Save the specific Uri that fiddler is hosted on for the next step.

Configuring the Unity Editor to use a Proxy

The reason Fiddler will not capture network traffic from the Unity editor is because Unity is running a custom version of Mono.  Fiddler can capture traffic from other processes because most processes will use the machines configuration for accessing the network which Fiddler automatically hooks into.   Since Mono does not use the machines configuration for accessing the internet it won’t know to go through Fiddler and instead goes directly to the internet.  The solution is to configure the Unity Editors version of Mono to go through Fiddler.   We do this by modifying the machine.config in the mono installation directory for the Unity Editor as shown below for Windows and MAC OS.

NOTE: Make sure to undo these changes after you are done testing your network code in Unity. Otherwise the network code will always try to go through the Fiddler proxy. This will end in server not found errors if Fiddler is not running.

 

 

 

 

 

 

 

 

 

 

 

 

Configuring Unity for Fiddler on Windows

  1. Shutdown all instances of Unity

  2. Open Windows Explorer and navigate to the following directory:
    C:\Program Files (x86)\Unity\Editor\Data\Mono\etc\mono\2.0

  3. Right click machine.config and choose properties

  4. Choose the security tab and click edit.  Add the account you are logged in as with read/write permissions and apply the changes.  NOTE: You may need to take ownership of the file.

  5. Open machine.config in a text editor as Administrator.

  6. Add the following to the <system.net> section and replace ‘ipaddress’ with the correct IP from the previous step. Do not add <system.net> again, it is shown for reference on where to put the <defaultProxy> section. 

     <system.net>
    <defaultProxy>
      <proxy proxyaddress="https://ipaddress:8888"/>
    </defaultProxy>
    
  7. Save machine.config

 

 

 

 

 

 

Configuring Unity for Fiddler on MAC OSX

  1. Shutdown all instances of Unity

  2. Open Finder and navigate to Application/Unity, right click on the Unity.app file and choose “Show package content”

  3. Navigate to Contents/Frameworks/mono/etc/mono/2.0

  4. Open machine.config in a text editor.

  5. Add the following to the <system.net> section and replace ‘ipaddress’ with the correct IP from the previous step.  Do not add <system.net> again, it is shown for reference on where to put the <defaultProxy> section:

     <system.net>
    <defaultProxy>
      <proxy proxyaddress="https://ipaddress:8888"/>
    </defaultProxy>
    
  6. Save machine.config

 

 

NOTE: Make sure to undo these changes after you are done testing your network code in Unity. Otherwise the network code will always try to go through the Fiddler proxy. This will end in server not found errors if Fiddler is not running.

Conclusions

Fiddler and Unity are now set up so that Fiddler will catch the network traffic from code running in the Unity Editor.  I hope the Unity developers writing network code will find this useful for testing their applications and working out the kinks for network services they might be connecting to.  Until next time have fun coding!

Don’t forget to follow the Windows Store Developer Solutions team on Twitter @wsdevsol. Comments are welcome, both below and on twitter.

- Bret Bentzinger(Microsoft) @awehellyeah

Comments

  • Anonymous
    February 19, 2015
    You don't actually need a Windows machine; you can run Fiddler on Linux on real hardware or in a VM on a Mac: blogs.telerik.com/.../running-fiddler-in-virtualbox-on-mac

  • Anonymous
    February 19, 2015
    The comment has been removed

  • Anonymous
    February 19, 2015
    Thanks for the tips for Linux/MAC.  Ill update the photo.  Missed that thanks.

  • Anonymous
    January 07, 2016
    I am trying to access a REST API from Unity. Both the API server and the Unity client are running on localhost and I need to see what exactly is being sent in the request. I have set up Fiddler to show traffic on localhost, and this is working fine when calling the REST services from the browser. But the calls made from Unity are not being captured. I am using Unity version 5.3.1f1 64 bit. I have added the proxy configuration to the system.net section as indicated, and I have tried with different parameters. This is my current configuration:      <defaultProxy>            <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://192.168.56.1:8888" usesystemdefault="false"/>      </defaultProxy> The IP adress shows Fiddler's default response when browsing from the server. What am I missing? Thank you.