`

How to debug your application (http protocol) using Fiddler

阅读更多

Fiddler has been out there for a while, but recently I discovered that it is either unknown, or not used, so I decided to write a short post on what it is, and how we can easily debug HTTP traffic (for example WCF Service calls) using it.

Before diving into essentials I would like to mention what it is. Fiddler is a debugging HTTP proxy(you can read more on what proxy server is here ). Being so, when started it automatically configures user’s system to use it.

So, here is a “Welcome” screen of Fiddler :

Where, you can see a Web Sessions list (1), Working area (2,3) which is split over Action tabs (2) and Information window part (3). From the Action tabs, you would spent most of the time inside “Inspectors” while you debug your http traffic.

Once you download, install and run it, you can check the Internet Connection settings, and you will notice that it has automatically configured the system to use a HTTP Proxy on address 127.0.0.1 (which is local machine) and port 8888:

Please note, that although the shortest way to go to “Internet options” if from the “Tools” –> “Options” menu from Internet Explorer, these options are not just “Internet Explorer Options”. These are system-wide internet connectivity options, and all windows based programs are reading them. So when this proxy is set, any program that relies on windows settings (and not its own settings) will use that proxy for HTTP connections.

So let’s see how to inspect a single HTTP request. Just install and run Fiddler. You can run fiddler either from Windows’ Start Menu, or from Internet Explorer’s “Tools” menu. Once you run it, just leave it open and navigate to a website of your choice. You will be surprised how many HTTP requests are issued for a single web page to load. Every single image you see, every single style loaded, every JavaScript load initiates a HTTP request. So pick up one of the requests (preferable some of the first requests, that will load the HTML) and go to Inspectors from Action tabs:

So, you see the selected web session (1), and you click on Inspectors (2). Well, the Inspectors information area is split horizontally on two parts. First part (3,4) is inspecting HTTP request issued by the client application, while the second (bottom) part (5,6) is inspecting the server response. On the image 3 and 5 are the different types of inspectors, while 4 & 6 are the information parts that shows information structured by the way of showing it (using 3 & 5). You will easily see that you can inspect the request by viewing it in:

  • Headers – showing only headers
  • TextView – showing plain text view of the request
  • WebForms – showing only variable names & values sent with the request (if you have some forms submitting some data)
  • HexView – shows hexadecimal representation of the request
  • Auth – showing just the Authentication headers (if present), so you can inspect issues with authentication
  • Raw – showing the Raw HTTP request (headers + body as sent by the client application)
  • XML – showing the request in XML tree navigation structure. It is very useful for visualizing XML RPC communication or SOAP communication, as it displays the XML in tree structure.

For the Response part of the screen you will see 3 additional types of displaying information:

  • Transformer – showing general information on the response, as well as response size
  • Caching – showing whether the response sent is cached
  • Privacy – showing any information, if present, regarding PGP privacy
  • Image View – showing the actual image, if the request was returning image

During development process we are more likely to run your application at “localhost”. What is localhost? Long explanation you can find here: http://en.wikipedia.org/wiki/Localhost . In basics, this your computer. And localhost is always resolved as IPv4 address 127.0.0.1 or IPv6 address ::1. Here comes the tricky part. You can read the FAQ Section on Debugging localhost . As explained, if your application launches on http://localhost:45960/WebSite1/Default.aspx , you can change the “localhost” to “ipv4.fiddler” (http://ipv4.fiddler:45960/WebSite1/Default.aspx ) and you will see the same page, but the traffic will go through fiddler.

The issue comes from the way localhost is interpreted by applications. Although a system proxy is configured, the applications (especially .NET based) automatically bypass proxy for this address. And you have no means (in .NET) to instruct application to use proxy server when connecting to localhost. So you have to use any other name to access your application. The tricky moment is that Cassini Web Server (Visual Studio development server) binds only to IPv4 address of 127.0.0.1. And you must somehow add another hostname that resolves to 127.0.0.1. The easiest, the smoothest way to do that without writing any code, without altering any configuration setting of your project, without changing the registry, is relying on the way windows DNS resolver works. On every windows machine (well at least since Windows XP & 2000 and later) there is one single plain text file, located on same place on all windows platforms (x86, x64) regardless of windows version:

c:\windows\system32\drivers\etc\hosts

It is a file without extension. In more recent versions of windows you have to be administrator (run notepad as administrator) in order to save changes to that file. It is very simple and its first lines are following:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

I open that file, and add a single line at the bottom:

127.0.0.1 developdemo

Now I know that whenever I type http://developdemo/ I will open the localhost (127.0.0.1). And whatever windows application makes a HTTP request to “developdemo” – it will be requesting information from localhost. And if Fiddler is running, it will log all and any HTTP requests that are going to and from developdemo host.

Well, I gave you the basics, and I hope that you now know that there is a way to debug your HTTP based application.

分享到:
评论

相关推荐

    SignalR – Real-time Application Development, 2nd (pdf英文原版第二版)

    With technology trends, demands on software have changed with more and more skilled ... Lastly, you will learn how to monitor the traffic in SignalR using Fiddler, Charles and hosting SignalR using OWIN.

    Fiddler 网络测试器

    Fiddler is freeware and can debug traffic from virtually any application that supports a proxy, including Internet Explorer, Google Chrome, Apple Safari, Mozilla Firefox, Opera, and thousands more....

    Fiddler web debug最新官方版

    【Fiddler Web Debug 最新官方版】 Fiddler 是一款强大的网络调试工具,由 Telerik 公司开发,主要用于捕获、分析和修改在浏览器与服务器之间的 HTTP/HTTPS 数据通信。这款工具对于开发者和测试人员来说是不可或缺...

    fiddler2

    Have you ever found yourself wondering how Microsoft Internet Explorer interacts with your Web application? Have you encountered a strange performance bottleneck that you can't track down? Are you ...

    HTTP调试工具 Fiddler

    HTTP调试工具 Fiddler可以帮您记录,调试Microsoft Internet Explorer与Web应用程序的交互,找到Web程序运行性能的瓶颈,还有如查看向Web服务器发送cookies的内容,下载内容的大小等功能。 说多一点是,Fiddler...

    Fiddler 4.6 自带fiddlerscript插件

    Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据,Fiddler包含了一个强大的基于事件脚本的子系统,并且能使用.net语言进行扩展...

    fiddler2 和 fiddler4 版本

    Fiddler是一款强大的网络调试工具,它允许开发者捕获、查看、修改HTTP(S)网络流量。这个工具由Telerik公司开发,广泛应用于Web应用程序的调试和性能测试。本文将详细介绍Fiddler2和Fiddler4的区别以及它们各自的功能...

    C#用FiddlerCore抓包HTTP和HTTPS源码

    using Fiddler; public class Program { static void Main() { FiddlerApplication.Prefs.SetBoolPref("fiddler.network.useproxy", true); FiddlerApplication.Startup(8888, true, true, true); // 监听...

    C# 调用FiddlerCore实现http/https抓包

    using Fiddler; public class Program { static void Main() { // 初始化FiddlerCore CoreRuntime.Startup(8888, true, false); // 设置FiddlerCore捕获HTTPS流量 FiddlerApplication.Prefs.SetBoolPref(...

    fiddler配置详情.docx

    - 在fiddler的`Tools` > `Fiddler Options` > `Connections`中,勾选`Allow remote computers to connect`,并记下端口号(默认为8888)。 2. **设置手机代理** - 让手机与电脑连接到同一个局域网,并获取电脑的...

    fiddler-mac.zip

    If you don’t have the Mono framework installed on your MAC, please, download it from http://www.mono-project.com/download/#download-mac and install it. If you already have it installed, please, ...

    Fiddler-web抓包工具学习文档

    Fiddler 中的断点功能能够允许开发者和测试人员在特定的 HTTP 流量上设置断点,从而能够更好地控制和 debug 应用程序。 Fiddler 中的 Script Fiddler 的 Script 系统能够允许开发者和测试人员使用 JavaScript 语言...

    HTTP调试工具 fiddler图文使用教程.docx

    HTTP调试工具Fiddler是一款强大的网络调试代理,它主要用于记录、调试Microsoft Internet Explorer与Web应用程序之间的交互。Fiddler能够帮助开发者找出Web程序性能瓶颈,查看HTTP通信中的cookies内容,以及详细分析...

    Fiddler 4.60 自带fiddlerscript插件

    Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据,Fiddler包含了一个强大的基于事件脚本的子系统,并且能使用.net语言进行扩展

    http分析器 -- Fiddler

    http分析器 -- Fiddler http分析器 -- Fiddler http分析器 -- Fiddler

    Fiddler安装包

    Fiddler抓包工具,安装前请安装.NET framework驱动,首先你要看清楚你的Fiddler配置的默认端口号是8888,这个端口号你后面是需要手动配置移动端无线网路代理的,这个后面会讲到。其次就是勾选上Allow remote ...

    fiddler中文免安装版

    **Fiddler中文免安装版详解** Fiddler是一款强大的网络封包分析工具,由Telerik公司开发,广泛应用于Web应用程序的调试、性能测试和安全评估。它能够捕获HTTP和HTTPS流量,帮助开发者深入了解网络通信过程,解决...

    Fiddler 2.3.5.2 HTTP调试工具

    软件名称:Fiddler v2.3.5.2 软件类别:HTTP调试工具 运行环境:Win2003, WinXp, Win2000, Win9x 授权方式:免费 软件介绍: Fiddler 是一款HTTP调试工具 ,可以帮您记录,调试Microsoft Internet Explorer与Web...

    Fiddler中文免安装.zip

    **Fiddler中文免安装.zip** 是一个专为Windows用户设计的压缩包,它包含了Fiddler的中文版本,无需安装即可直接使用。Fiddler是一款强大的网络调试工具,由Telerik公司开发,广泛应用于软件开发、测试和网络监控等...

    Fiddler2 http tools

    Fiddler2 Fiddler2 Fiddler2 Fiddler2 Fiddler2 Fiddler2

Global site tag (gtag.js) - Google Analytics