Fiddler Tutorial Series (1) Getting to know Fiddler for the first time, what can we do with fiddler?

Fiddler is one of the most powerful and useful web debugging tools. It can record all client and server http and https requests, allowing you to monitor, set breakpoints, and even modify input and output data. Use Fiddler for both development and testing. It's all of great help.

Reading table of contents

  1. Basic introduction to Fiddler
  2. How Fiddler works
  3. Other similar tools
  4. How Fiddler captures Firefox's session
  5. Using the Fiddler plug-in in Firefox
  6. How Fiddler captures HTTPS sessions
  7. Fiddler’s basic interface
  8. Fiddler’s statistics view
  9. Use of QuickExec command line
  10. Set breakpoints in Fiddler to modify Request
  11. Set breakpoints to modify Response in Fiddler
  12. Create AutoResponder rules in Fiddler
  13. How to filter sessions in Fiddler
  14. Session comparison function in Fiddler
  15. Coding gadgets provided in Fiddler
  16. Query session in Fiddler
  17. Save session in Fiddler
  18. Fiddler's script system
  19. How to use Fiddler when debugging a website in VS
  20. Response is garbled

Basic introduction to Fiddler

Fiddler's official website: www.fiddler2.com

The official Fiddler website provides a large number of help documents and video tutorials, which are the best materials for learning Fiddler.

Fiddler is one of the most powerful and useful web debugging tools. It can record all client and server http and https requests, allowing you to monitor, set breakpoints, and even modify input and output data. Fiddler contains a powerful tool based on A subsystem for event scripting and can be extended using .net language

The more you understand the HTTP protocol, the better you can master how to use Fiddler. The more you use Fiddler, the more it will help you understand the HTTP protocol.

Fiddler is a very useful tool for both developers and testers

How Fiddler works

Fiddler works as a proxy web server. It uses proxy address: 127.0.0.1, port: 8888. When Fiddler automatically sets the proxy, it will automatically log out of the proxy when exiting, so that it will not affect other programs. However, if Fiddler exits abnormally, the web page will be inaccessible because Fiddler does not log out automatically. The solution is to restart Fiddler.

Other similar tools

Similar tools include: httpwatch, firebug, wireshark

How to capture Firefox session with Fiddler

The data packets of any program that can support HTTP proxy can be sniffed by Fiddler. The operating mechanism of Fiddler is actually an HTTP proxy that listens to port 8888 on the local machine. When Fiddler2 starts, the default IE proxy is set to 127.0.0.1:8888, while other browsers need to be set manually, so change the Firefox proxy to 127.0.0.1:8888 to monitor data.

Set the proxy on Firefox by following the steps below

Click: Tools -> Options, click Advanced tab -> network tab -> setting on the Options dialog box.

Install the Fiddler plug-in in Firefox

Modifying the proxy in Firefox is troublesome, and you have to remove the proxy when you don't use fiddler. trouble

It is recommended that you use the fiddler hook plug-in in firefox, so that you can use Fiddler to get the request and response in firefox very conveniently.

After you install fiddler, the Fiddler hook plug-in has been installed. You need to enable this plug-in in firefox. Open
firefox tools->Add ons->Extensions and start FiddlerHook.

How Fiddler captures HTTPS sessions

By default, Fiddler will not capture HTTPS sessions, you need to set it up, open Fiddler Tool->Fiddler Options->HTTPS tab

Select the checkbox, the following dialog box will pop up, click "YES"

After clicking "Yes", it is set up

Fiddler’s basic interface

Take a look at Fiddler’s basic interface

There are many messages for viewing Request or Response under the Inspectors tab. The Raw Tab can view the complete message, and the Headers tab only views the headers in the message. As shown below

Fiddler’s HTTP statistics view

By displaying all HTTP traffic, Fiddler can easily show you which files generated the page you are currently requesting. Using the Statistics tab, users can select multiple sessions to get the total information statistics of these sessions, such as multiple requests and the number of bytes transferred.

Select the first request and the last request to get the overall time it took for the entire page to load. From the bar chart, you can also identify which requests take the most time to optimize the access speed of the page.

Use of QuickExec command line

There is a command line tool called QuickExec in the lower left corner of Fiddler, which allows you to enter commands directly.

Common commands include

help opens the official usage page introduction, all commands will be listed

cls clears the screen (Ctrl+x can also clear the screen)

select command to select a session

?.png is used to select images with png suffix

bpu intercepts request

Set breakpoints in Fiddler to modify Request

The most powerful function of Fiddler is to set breakpoints. After setting breakpoints, you can modify any information of httpRequest including host, cookie or data in the form. There are two ways to set breakpoints

The first one: Open Fiddler and click Rules-> Automatic Breakpoint -> Before Requests (this method will interrupt all sessions)

How to eliminate the command? Click Rules->Automatic Breakpoint->Disabled

Second: Enter the command on the command line: bpu www.baidu.com (this method will only interrupt www.baidu.com)

How to eliminate the command? Enter the command bpu on the command line

Let's take an example to simulate the login of the blog park. Open the login page of the blog park in IE, enter the wrong user name and password, use Fiddler to interrupt the session, and change the user name and password to the correct one. This will enable you to log in successfully

1. Use IE to open the login interface of Blog Park http://passport.cnblogs.com/login.aspx
2. Open Fiddler and enter bpu http://passport.cnblogs.com/login.aspx in the command line
3. Enter Incorrect username and password, click Login
4. Fiddler can interrupt this session, select the interrupted session, click the WebForms tab under the Inspectors tab to change the username and password, and then click Run to Completion as shown in the figure below.
5. The result is that you have logged in to the blog park correctly.

Set breakpoints to modify Response in Fiddler

Of course, the Response can also be modified in Fiddler

The first one: Open Fiddler and click Rules->Automatic Breakpoint->After Response (this method will interrupt all sessions)

How to eliminate the command? Click Rules->Automatic Breakpoint->Disabled

Second: Enter the command on the command line: bpafter www.baidu.com (This method will only interrupt www.baidu.com)

How to eliminate the command? Enter the command bpafter on the command line,

The specific usage is similar to the previous section, so I won’t go into details.

Create AutoResponder rules in Fiddler

Fiddler's AutoResponder tab allows you to return files locally without sending an http request to the server.

Let’s look at an example. 1. Open the home page of Blog Park, save the logo image of Blog Park locally, and make some modifications to the image.

2. Open Fiddler and find the session with the logo image, http://static.cnblogs.com/images/logo_2012_lantern_festival.gif, drag this session to the AutoResponer Tab

3. Select Enable automatic reaponses and Unmatched requests passthrough

4. Select Find a file... under the Rule Editor below and select the locally saved image. Finally, click Save to save it.

5. Use the IE Blog Park homepage again, and you will see that the pictures on the homepage are local.

How to filter sessions in Fiddler

Every time I use Fiddler and open a website, I can see dozens of sessions in Fiddler, which is dazzling. The best way is to filter out some conversations, such as filtering out picture conversations. Fiddler has a filtering function. In the Filters tab on the right, there are many options. After a little research, you will know how to use it.

Session comparison function in Fiddler

Select 2 sessions, right-click and click Compare, you can use WinDiff to compare the differences between the two sessions (of course you need to install WinDiff)

Coding gadgets provided in Fiddler

Click TextWizard on the Fiddler toolbar. This tool can Encode and Decode string.

Query session in Fiddler

Use the shortcut key Ctrl+F to open the Find Sessions dialog box, enter keywords to query the session you want. The queried sessions will be displayed in yellow

Save session in Fiddler

Sometimes we need to save the conversation so that it can be sent to others or analyzed later. Here are the steps to save a session:

Select the session you want to save and click File->Save->Selected Sessions

Fiddler's script system

The most complicated thing about Fiddler is the script system. Official help document: http://www.fiddler2.com/Fiddler/dev/ScriptSamples.asp

First install the SyntaxView plug-in, Inspectors tab->Get SyntaxView tab->Download and Install SyntaxView Now... as shown below

After successful installation, Fiddler will have an additional Fiddler Script tab, as shown below

In it we can write scripts. Let's look at an example to make all cnblogs sessions display red.

Place this script under the OnBeforeRequest(oSession: Session) method and click "Save script"

     if (oSession.HostnameIs("www.cnblogs.com")) {
            oSession["ui-color"] = "red";
        }

In this way, all cnblogs sessions will be displayed in red.

How to use Fiddler when debugging a website in VS

When we use visual studio to develop ASP.NET websites, we also need to use Fiddler to analyze HTTP. By default, Fiddler cannot sniff localhost websites. But as long as you add a period after localhost, Fiddler can sniff it.

For example: The original address of ASP.NET is http://localhost:2391/Default.aspx. After adding a period, it becomes http://localhost.:2391/Default.aspx.

The second method is to add 127.0.0.1 localsite to the hosts file

How do you access http://localsite:port number. In this way, Fiddler can also intercept it.

Response is garbled

Sometimes we see that the HTML in the Response is garbled. This is because the HTML is compressed. We can decompress it in two ways.

1. 点击Response Raw上方的"Response is encoded any may need to be decoded before inspection. click here to transform"

2. Select "Decode" in the toolbar. This will automatically decompress it.

Guess you like

Origin blog.csdn.net/a448335587/article/details/132716618