开发者

Log Fiddler Requests to Database Real-time

开发者 https://www.devze.com 2023-04-07 01:23 出处:网络
Is there any way to log all requests ongoing to a database or can you only log snapshots to开发者_开发百科 a database?The following example relies upon OLEDB 4.0 which is not available for 64bit proce

Is there any way to log all requests ongoing to a database or can you only log snapshots to开发者_开发百科 a database?


The following example relies upon OLEDB 4.0 which is not available for 64bit processes. You can either select another data provider (e.g. SQLServer) or you can force Fiddler to run in 32bit mode.

Add the following to the Rules file to create a new menu item.

// Log the currently selected sessions in the list to a database.
// Note: The DB must already exist and you must have permissions to write to it.
public static ToolsAction("Log Selected Sessions") 
function DoLogSessions(oSessions: Fiddler.Session[]){
if (null == oSessions || oSessions.Length < 1){
  MessageBox.Show("Please select some sessions first!");
  return;
}
var strMDB = "C:\\log.mdb";
var cnn = null;
var sdr = null;
var cmd = null;
try
{
  cnn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strMDB);
  cnn.Open();
  cmd = new OleDbCommand();
  cmd.Connection = cnn;

  for (var x = 0; x < oSessions.Length; x++){
    var strSQL = "INSERT into tblSessions ([ResponseCode],[URL]) Values (" + 
    oSessions[x].responseCode + ", '" + oSessions[x].url + "')";
    cmd.CommandText = strSQL;
    cmd.ExecuteNonQuery();
  }
}
catch (ex){
  MessageBox.Show(ex);
}
finally
{
  if (cnn != null ){
    cnn.Close();
  }
}
}

Note: To use the Database Objects in Fiddler 2.3.9 and below, you'll need to add system.data to the References list inside Tools | Fiddler Options | Extensions | Scripting. In 2.3.9.1 and later, this reference will occur automatically. Then, list the new import at the top of your rules script:

import System.Data.OleDb;

see FiddlerScript CookBook

0

精彩评论

暂无评论...
验证码 换一张
取 消