Use Fiddler2 's custom rules to automatically capture the app's token and document it

Source: Internet
Author: User
Tags fiddler2

The original Kun Peng (http://www.site-digger.com)

This article original link: http://www.site-digger.com/html/articles/20170810/137.html




background: the token of an app is time-sensitive, with an approximate life cycle of only one hour. Therefore, the crawler can not use a fixed token to capture data, must be timed to obtain a new token value. However, token generation process is difficult to achieve directly.

Kun's technical staff after research, and finally adopted the "curve Save the Nation" method, through the program simulation operation of the app (start), timed to generate a new token, and then use Fiddler2 capture the token and recorded in the specified file (crawler timed to read this file to obtain a new token).

capture the app's packet with Fiddler2 This method has been mentioned many times in our previous article, if you are not familiar with it, you can look here http://www.site-digger.com/html/articles/20170116/134.html . Today we will focus on how to let Fiddler2 automatically record the specific parameters captured to the specified file.

thanks to the custom Rules feature of Fiddler2, we can add scripts (JavaScript) to custom rules to implement the customized functionality. Official website Sample document:http://docs.telerik.com/fiddler/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse.

The following are the steps:

The first step: start fiddler Scripteditor. "Menu bar rules--Customize rules ..." as shown in:

Step Two: Locate the Onbeforerequest () method and insert the following code:

View Plaincopy to Clipboardprint?

  1. //First determine if the requesting domain name is of interest to you, and whether the URL contains a feature string of interest to you. If it is, the URL and querystring of the request are logged to the log file "C:/fiddler-token.log".   

  2. if(Osession.hostnameis ("A domain name") && Osession.uricontains ("feature string")){  

  3.         var  filename =  "C:/fiddler-token.log" ;  

  4. var curdate = New  Date ();

  5. varlogcontent ="["+ curdate.tolocalestring () +"] "+ osession.pathandquery +"\ r \ n";

  6.         var  sw : system.io.streamwriter;  

  7. if (System.IO.File.Exists (filename)) {

  8. SW = System.IO.File.AppendText (filename);

  9. Sw. Write (logcontent);

  10. }

  11. Else {  

  12. SW = System.IO.File.CreateText (filename);

  13. Sw. Write (logcontent);

  14. }

  15. Sw. Close ();

  16. Sw. Dispose ();

  17. }

Step Three: Save the script and test (takes effect immediately after saving, without restarting Fiddler). The test results are as shown.


Description: The article for Kun Peng (http://www.site-digger.com) original article, you can comment, but also can be reproduced to other sites, but please keep the source address, thank you!! (respect for the work of others, we work together)


Use Fiddler2 's custom rules to automatically capture the app's token and document it

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.