No extra effort to view JSON output at any time
"No extra effort" means that when you need to look at the JSON output, just turn the eyeball (and maybe at least two more clicks) to find the result quickly.
There are a lot of ways to view JSON output, and the closest we can get to this goal is "Fiddler2+jsonviewer plugin + custom Fiddler2 filter conditions." To view the JSON output, just run the fiddler first, and then in the browser normal operation of the Web page, you can see in the Fiddler of the captured JSON output, the effect shown in the following figure.
Installing the Fiddler2+jsonviewer Plugin
Fiddler2 is a veteran web debugging tool. After downloading and installing, click "Start | program | Fiddler2 "or click IE Menu" tool | Fiddler2 "It will automatically register itself as an IE proxy server, so as to intercept any request/response through IE; when you close it, it automatically cancels the proxy server configuration (when you use Fiddler1, you have to add your own proxy server configuration, Very troublesome to say).
Jsonviewer is a small tool for viewing JSON objects. After decompression, you can see 3 subdirectories:
-Jsonview: Can be run independently version.
-visualizer:vs2005 plugin.
-Fiddler:fiddler2 plugin.
We're going to install the Jsonviewer Fiddler2 plugin next. To do this, copy all the files in the Fiddler directory to the Fiddler2 installation directory \inspectors\. Then modify the "Fiddler2 installation directory \fiddler.exe.config", as shown in the following figure, and the bold part is the configuration information we need to add.
Copy Code code as follows:
<configuration>
<runtime>
<generatepublisherevidence enabled= "false"/>
<assemblybinding xmlns= "Urn:schemas-microsoft-com:asm.v1" >
<probing privatepath= "Inspectors"/>
</assemblyBinding>
</runtime>
</configuration>
Note that the IE7 and the. NET Framework are hard-coded into a proxy server as long as it is a request to localhost. So requests like "http://localhost:8000/Default.aspx" are not intercepted by Fiddler2. The workaround is: 1 replace "localhost" with "localhost.", such as "http://localhost.:8000/Default.aspx" and 2, substituting "localhost" for the cost machine IP address, such as "http:// 172.16.75.78:8000/default.aspx ".
Now let's run the Fiddler2 and then manipulate the page to see a bunch of requests/responses in the Web Sessions list on the left side of the Fiddler2 form. Click to return to JSON, and then click the "inspectors" and "Json" tab on the right side to go. Just, Fiddler2 by default will all go through IE any request/answer all show out, so, "Web Sessions" list of Dongdong too much, can not all the things with JSON filter out? This is not difficult, just add a few lines of code to the Fiddler2 "Customrules".
Custom filter conditions
Click on the Fiddler2 menu "rules| Customize rules ... "Automatically opens a code file that you can add a custom rule to by Notepad.
Add the following code on line 81st to add a "JSON-only" menu item to the FIDDLER2 rules menu:
jcl20091121
public static Rulesoption ("show &json Only")
var M_showjsononly:boolean = false;
Add the following code in the Onbeforeresponse event, which means that if the "rules| only show JSON" menu item is selected, it filters out all content-type!= "Application/json;" Charset=utf-8 "answer.
Copy Code code as follows:
Jcl:2009-11-21
if (m_showjsononly) {
MessageBox.Show (OSession.oResponse.headers.Item ("Content-type"). ToString ());
if (!osession.oresponse.headers.existsandcontains ("Content-type", "Application/json; Charset=utf-8 ")) {
osession["ui-hide"] = "Hide"; String Value not important
}
}
All source code here:
Custom Rules
Copy Code code as follows:
Import System;
Import System.Windows.Forms;
Import Fiddler;
Globalization Note:
Be sure to save the file with UTF-8 Encoding if using any non-ascii characters
in strings, etc.
//
JScript Reference
Http://www.fiddler2.com/redir/?id=msdnjsnet
//
Fiddlerscript Reference
Http://www.fiddler2.com/redir/?id=fiddlerscriptcookbook
//
Fiddlerscript Editor:
Http://www.fiddler2.com/redir/?id=fiddlerscripteditor
Class handlers
{
The following snippet demonstrates a custom-bound column for the Web sessions list.
Http://www.fiddler2.com/fiddler/help/configurecolumns.asp for more info
public static Binduicolumn (' method ', 60)
function Fillmethodcolumn (os:session) {
if ((os.orequest!= null) && (oS.oRequest.headers!= null))
return oS.oRequest.headers.HTTPMethod; else return String.Empty;
//}
public static rulesoption ("Hide 304s")
var M_hide304s:boolean = false;
Cause Fiddler to override the Accept-language header with one of the defined values
public static rulesoption ("Request &japanese Content")
var M_japanese:boolean = false;
Cause Fiddler to override the User-agent header with one of the defined values
Rulesstring ("&user-agents", True)
Rulesstringvalue (0, "Netscape &3", "mozilla/3.0" (Win95; I) ")
Rulesstringvalue (1, "&iemobile", "mozilla/4.0" (compatible; MSIE 6.0; Windows CE; Iemobile 6.12) ")
Rulesstringvalue (2, "&safari (XP)", "mozilla/5.0 (Windows; U Windows NT 5.2; En-US) applewebkit/531.9 (khtml, like Gecko) version/4.0.3 safari/531.9.1 ")
Rulesstringvalue (3, "IE &6 (XPSP2)", "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.1; SV1) ")
Rulesstringvalue (4, "IE &7 (Vista)", "mozilla/4.0" (compatible; MSIE 7.0; Windows NT 6.0; SLCC1) ")
Rulesstringvalue (5, "IE &8 (Win2k3 x64)", "mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; WOW64; trident/4.0) ")
Rulesstringvalue (6, "IE 8 (Win7)", "mozilla/4.0" (compatible; MSIE 8.0; Windows NT 6.1; trident/4.0) ")
Rulesstringvalue (7, "IE 8 (IE7 compatmode)", "mozilla/4.0" (compatible; MSIE 7.0; Windows NT 5.1; trident/4.0) ")
Rulesstringvalue (8, "&opera", "opera/9.80" (Windows NT 5.2; U EN) presto/2.2.15 version/10.00 ")
Rulesstringvalue (9, "&firefox 2", "mozilla/5.0" (Windows; U Windows NT 5.1; En-us; rv:1.8.1.10) gecko/20071115 firefox/2.0.0.10 ")
Rulesstringvalue ("&firefox 3.5", "mozilla/5.0" (Windows; U Windows NT 5.2; En-us; rv:1.9.1.3) gecko/20090824 firefox/3.5.3 ")
Rulesstringvalue ("&firefox (MAC)", "mozilla/5.0" (Macintosh; U Intel Mac OS X 10.6; En-us; rv:1.9.1.3) gecko/20090824 firefox/3.5.3 ")
Rulesstringvalue ("Chrome", "mozilla/5.0") (Windows; U Windows NT 5.2; En-US) applewebkit/532.0 (khtml, like Gecko) chrome/3.0.195.24 safari/532.0 ")
Rulesstringvalue ("&custom", "%custom%")
public static var sua:string = null;
Cause Fiddler to delay HTTP traffic to simulate typical 56k modem conditions
public static rulesoption ("Simulate &modem speeds", "per&formance")
var M_simulatemodem:boolean = false;
Removes http-caching related headers and specifies "No-cache" on requests and responses
public static rulesoption ("&disable Caching", "per&formance")
var M_disablecaching:boolean = false;
Show the duration between the "start of Request.send" and response.completed in milliseconds
public static rulesoption ("&show time-to-last-byte", "per&formance")
var M_showttlb:boolean = false;
Show the time of response completion
public static Rulesoption ("Show Response ×tamp", "per&formance")
var M_showtimestamp:boolean = false;
Create a new option on the Rules menu. Set the default value for the option.
public static rulesoption ("&untitled")
var M_buntitled:boolean = false;
Create a new item on the Tools menu.
public static toolsaction ("&untitled")
function dountitled (osessions:fiddler.session[]) {
Write Your code here
}
jcl20091121
public static Rulesoption ("show &json Only")
var M_showjsononly:boolean = false;
Force A manual reload of the script file. Resets all
Rulesoption variables to their defaults.
public static toolsaction ("Reset Script")
function Domanualreload () {
Fiddlerobject.reloadscript ();
}
public static contextaction ("Decode Selected Sessions")
function doremoveencoding (osessions:session[]) {
for (var x = 0; x < Osessions.length + +) {
Osessions[x].utildecoderequest ();
Osessions[x].utildecoderesponse ();
}
}
static function Onboot () {
MessageBox.Show ("Fiddler has finished booting");
System.Diagnostics.Process.Start ("Iexplore.exe");
FiddlerObject.UI.ActivateRequestInspector ("HEADERS");
FiddlerObject.UI.ActivateResponseInspector ("HEADERS");
}
static function OnShutdown () {
MessageBox.Show ("Fiddler has shutdown");
}
static function Onattach () {
MessageBox.Show ("Fiddler is now" system proxy);
System.Diagnostics.Process.Start ("Proxycfg.exe", "U"); Notify WinHTTP of proxy change
}
static function Ondetach () {
MessageBox.Show ("Fiddler is no longer the system proxy");
System.Diagnostics.Process.Start ("Proxycfg.exe", "U"); Notify WinHTTP of proxy change
}
static function Onbeforerequest (osession:session)
{
Sample Rule:color ASPX Requests in RED
if (Osession.uricontains (". aspx")) {osession["ui-color"] = "Red";}
Sample Rule:flag POSTs to fiddler2.com in italics
if (Osession.hostnameis ("www.fiddler2.com") && Osession.httpmethodis ("POST")) {osession["ui-italic"] = " Yup "; }
Sample Rule:break requests for URLs containing "/sandbox/"
if (Osession.uricontains ("/sandbox/")) {
osession.oflags["x-breakrequest"] = "yup"; Existence of the X-BREAKREQUEST flag creates a breakpoint; The "Yup" value is unimportant.
// }
if ((null!= gs_replacetoken) && (oSession.url.indexOf (Gs_replacetoken) >-1)) {//Case sensitive
Osession.url = OSession.url.Replace (Gs_replacetoken, Gs_replacetokenwith);
}
if ((null!= gs_overridenhost) && (oSession.host.toLowerCase () = = Gs_overridenhost)) {
osession["x-overridehost"] = Gs_overridehostwith;
}
if ((Null!=bprequesturi) && osession.uricontains (Bprequesturi)) {
osession["X-breakrequest"]= "uri";
}
if ((Null!=bpmethod) && (Osession.httpmethodis (Bpmethod)) {
osession["X-breakrequest"]= "method";
}
if ((Null!=uibolduri) && osession.uricontains (Uibolduri)) {
osession["Ui-bold"]= "quickexec";
}
if (M_simulatemodem) {
Delay sends by 300ms per KB uploaded.
osession["Request-trickle-delay"] = "300";
}
if (m_disablecaching) {
OSession.oRequest.headers.Remove ("If-none-match");
OSession.oRequest.headers.Remove ("If-modified-since");
osession.orequest["Pragma"] = "No-cache";
}
User-agent Overrides
if (null!= SUA) {
osession.orequest["user-agent"] = SUA;
}
if (M_japanese) {
osession.orequest["accept-language"] = "JA";
}
}
static function Onbeforeresponse (osession:session)
{
if (M_simulatemodem) {
Delay receives by 150ms per KB downloaded.
osession["Response-trickle-delay"] = "150";
}
if (m_disablecaching) {
OSession.oResponse.headers.Remove ("Expires");
osession.oresponse["Cache-control"] = "No-cache";
}
if (M_showtimestamp) {
osession["Ui-customcolumn"] = DateTime.Now.ToString ("h:mm:ss.ffff") + "" + osession["Ui-customcolumn"];
}
if (m_showttlb) {
osession["Ui-customcolumn"] = OSession.oResponse.iTTLB + "MS" + osession["Ui-customcolumn"];
}
if (m_hide304s && osession.responsecode = 304) {
osession["ui-hide"] = "true";
}
if ((bpstatus>0) && (Osession.responsecode = = Bpstatus)) {
osession["X-breakresponse"]= "status";
}
if ((Null!=bpresponseuri) && osession.uricontains (Bpresponseuri)) {
osession["X-breakresponse"]= "uri";
}
Jcl:2009-11-21
if (m_showjsononly) {
MessageBox.Show (OSession.oResponse.headers.Item ("Content-type"). ToString ());
if (!osession.oresponse.headers.existsandcontains ("Content-type", "Application/json; Charset=utf-8 ")) {
osession["ui-hide"] = "Hide"; String Value not important
}
}
Uncomment to reduce incidence of ' unexpected socket closure ' exceptions in. NET code.
This is the really should also fix your. NET code to gracefully handle the unexpected.
//
if (!) ( ((Osession.responsecode = = 401) && osession.oresponse["Www-authenticate"]. Length > 9) | |
((Osession.responsecode = = 407) && osession.oresponse["Proxy-authenticate"]. Length > 9)) {
osession.oresponse["Connection"] = "close";
// }
}
static function Main ()
{
var today:date = new Date ();
Fiddlerobject.statustext = "Customrules.js is loaded at:" + Today;
Uncomment to add a "server" column containing the response "server" header, if present
FiddlerObject.UI.lvSessions.AddBoundColumn ("Server", "@response. Server");
}
These static variables are used for simple breakpointing & other quickexec rules
static var bprequesturi:string = null;
static var bpresponseuri:string = null;
static var bpstatus:int =-1;
static var bpmethod:string = null;
static var uibolduri:string = null;
static var gs_replacetoken:string = null;
static var gs_replacetokenwith:string = null;
static var gs_overridenhost:string = null;
static var gs_overridehostwith:string = null;
The Onexecaction function is called by either the Quickexec box in the Fiddler window,
or by the ExecAction.exe command line utility.
static function Onexecaction (sparams:string[]) {
Fiddlerobject.statustext = "Execaction:" + sparams[0];
var saction = Sparams[0].tolowercase ();
Switch (saction) {
Case "Bold":
if (sparams.length<2) {uibolduri=null; fiddlerobject.statustext= "bolding cleared"; return;}
Uibolduri = sparams[1]; Fiddlerobject.statustext= "bolding requests for" + Uibolduri;
Break
Case "BP":
Fiddlerobject.alert ("BPU = Breakpoint Request for uri\nbpm = Breakpoint Request Method\nbps=breakpoint Response Pafter = Breakpoint response for URI ");
Break
Case "bps":
if (sparams.length<2) {bpstatus=-1; fiddlerobject.statustext= "Response Status breakpoint cleared"; return;}
Bpstatus = parseint (sparams[1]); fiddlerobject.statustext= "Response Status breakpoint for" + sparams[1];
Break
Case "BPV":
Case "BPM":
if (sparams.length<2) {bpmethod=null; Fiddlerobject.statustext= "Request method breakpoint cleared"; return;}
Bpmethod = Sparams[1].touppercase (); Fiddlerobject.statustext= "Request method Breakpoint for" + Bpmethod;
Break
Case "BPU":
if (sparams.length<2) {bprequesturi=null; fiddlerobject.statustext= "RequestUri breakpoint cleared"; return;}
if (Sparams[1].tolowercase (). StartsWith ("http://")) {sparams[1] = sparams[1]. Substring (7);}
Bprequesturi = sparams[1];
fiddlerobject.statustext= "RequestUri breakpoint for" +sparams[1];
Break
Case "Bpafter":
if (sparams.length<2) {bpresponseuri=null; fiddlerobject.statustext= "ResponseUri breakpoint cleared"; return;}
if (Sparams[1].tolowercase (). StartsWith ("http://")) {sparams[1] = sparams[1]. Substring (7);}
Bpresponseuri = sparams[1];
fiddlerobject.statustext= "ResponseUri breakpoint for" +sparams[1];
Break
Case "Overridehost":
if (sparams.length<3) {gs_overridenhost=null; fiddlerobject.statustext= "Host Override cleared"; return;}
Gs_overridenhost = Sparams[1].tolowercase ();
Gs_overridehostwith = sparams[2];
fiddlerobject.statustext= "Connecting to [" + Gs_overridehostwith + "] for requests to [" + Gs_overridenhost +] ";
Break
Case "Urlreplace":
if (sparams.length<3) {gs_replacetoken=null; fiddlerobject.statustext= "URL replacement cleared"; return;}
Gs_replacetoken = sparams[1];
Gs_replacetokenwith = sparams[2]. Replace ("", "%20"); Simple Helper
fiddlerobject.statustext= "replacing [" + Gs_replacetoken + "] in URIs with [" + Gs_replacetokenwith +] ";
Break
Case "SELECT":
if (sparams.length<2) {fiddlerobject.statustext= "Please specify Content-type to select." return;}
FiddlerObject.UI.actSelectSessionsWithResponseHeaderValue ("Content-type", sparams[1]);
MessageBox.Show (Sparams[1]);
Fiddlerobject.statustext= "Selected Sessions returning Content-type:" + sparams[1] + ".";
if (FiddlerObject.UI.lvSessions.SelectedItems.Count > 0) {
FiddlerObject.UI.lvSessions.Focus ();
}
Break
Case "Allbut":
Case "Keeponly":
if (sparams.length<2) {fiddlerobject.statustext= "Please specify content-type to retain during wipe."; return;}
FiddlerObject.UI.actSelectSessionsWithResponseHeaderValue ("Content-type", sparams[1]);
MessageBox.Show (Sparams[1]);
FiddlerObject.UI.actRemoveUnselectedSessions ();
FiddlerObject.UI.lvSessions.SelectedItems.Clear ();
fiddlerobject.statustext= "Removed all but Content-type:" + sparams[1];
Break
Case "Stop":
FiddlerObject.UI.actDetachProxy ();
Break
Case "Start":
FiddlerObject.UI.actAttachProxy ();
Break
Case "CLS":
Case "Clear":
FiddlerObject.UI.actRemoveAllSessions ();
Break
Case "G":
Case "Go":
FiddlerObject.UI.actResumeAllSessions ();
Break
Case "Help":
Utilities.launchhyperlink ("Http://www.fiddler2.com/redir/?id=quickexec");
Break
Case "Hide":
FiddlerObject.UI.actMinimizeToTray ();
Break
Case "Nuke":
FiddlerObject.UI.actClearWinINETCache ();
FiddlerObject.UI.actClearWinINETCookies ();
Break
Case "Show":
FiddlerObject.UI.actRestoreWindow ();
Break
Case "tail":
if (sparams.length<2) {fiddlerobject.statustext= "Please specify # of sessions to trim"; return;}
FiddlerObject.UI.TrimSessionList (int. Parse (sparams[1]));
Break
Case "Quit":
FiddlerObject.UI.actExit ();
Break
Case "Dump":
FiddlerObject.UI.actSelectAll ();
FiddlerObject.UI.actSaveSessionsToZip (CONFIG. GetPath ("captures") + "Dump.saz");
FiddlerObject.UI.actRemoveAllSessions ();
Fiddlerobject.statustext = "Dumped all sessions to" + CONFIG. GetPath ("captures") + "dump.saz";
Break
Default
if (Saction.startswith ("http") | | saction.startswith ("www") {
System.Diagnostics.Process.Start (saction);
}
Else
Fiddlerobject.statustext = "Requested execaction:" + saction + "not found." Type Help to learn more. ";
}
}
}
Now the "Web Sessions" list has been much more refreshing, but, if we want to sneak in and visit the home page of the blog, we will find that the "Web Sessions" list contains several more than a few blog home page JSON output, this is because FIDDLER2 will intercept all requests via IE by default Answer Would it be possible for it to show only the local request/response? This only needs to be configured with the FIDDLER2 filter option, as shown in the following figure.