目录
1、抓本地包:
2、按URL过滤:
3、拦截脚本:
4、FiddlerScript:
4.1、OnBeforeResponse:
4.2、文件操作:
4.3、添加菜单按钮
4.4、csv文件的处理
4.5、列表操作
4.6、JSON操作
4.7、JScript(C#)
4.7.1、object[]转byte[]
在IP地址后面加个点:127.0.0.1.
或者直接用外部地址:192.168.X.X,就不需要加点号了
JScript.Net语法:http://doc.51windows.net/jscript5/?url=/jscript5/dir.htm
C#语法:在脚本中可以直接使用C#语法,只是定义变量是采用 var varName:varType的方式,直接用C#代码需要import包
可以对响应体内容进行修改,这里响应体内是拦截的是Java后台用GZip压缩的数据,这里处理后返回原数据:
static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}
if (oSession.fullUrl.Contains("YSSUCOBRIDGE")) {
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var respStr = oSession.GetResponseBodyAsString();
var respByte: byte[] = Convert.FromBase64String(respStr);
var depressedByte: byte[] = Utilities.GzipExpand(respByte);
var depressStr = Convert.ToBase64String(depressedByte);
var e = depressStr;
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (f < e.length) {
s = _keyStr.indexOf(e.charAt(f++));
o = _keyStr.indexOf(e.charAt(f++));
u = _keyStr.indexOf(e.charAt(f++));
a = _keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u != 64) {
t = t + String.fromCharCode(r)
}
if (a != 64) {
t = t + String.fromCharCode(i)
}
}
depressStr = utf8_decode(t);
oSession.utilSetResponseBody(depressStr);
}
}
static function utf8_decode(e: String): String {
var t = "";
var n = 0;
var r = 0;
var c1 = 0;
var c2 = 0;
var c3 = 0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3
}
}
return t;
}
其中depressStr为每个请求写入文件的内容:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("C:\\Users\\Administrator\\Desktop\\output.xls", true);
a.WriteLine("input");
for (var i:int = 0; i < reqArr.length; i++) {
try {
if (String.IsNullOrWhiteSpace(reqArr[i])) {
continue;
}
a.WriteLine(reqArr[i]);
} catch (ex:Exception) {
}
}
a.Close();
reqArr = new Array();
FiddlerObject.alert("保存成功");
https://www.cnblogs.com/zhm450/p/6770595.html?utm_source=itdadao&utm_medium=referral
https://www.cnblogs.com/weekend001/p/3475980.html
public static ToolsAction("FAST Print")
function FASTPrint(){
var str = "";
for (var n:int = 0; n < reqArr.length; n++) {
str += reqArr[n] + "\r\n";
}
FiddlerObject.alert(str);
}
public static ToolsAction("FAST Clear")
function FASTClear(){
reqArr = new Array();
}
public static ToolsAction("FAST Save")
function FASTSave(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("C:\\Users\\Administrator\\Desktop\\output.xls", true);
a.WriteLine("input");
for (var i:int = 0; i < reqArr.length; i++) {
try {
if (String.IsNullOrWhiteSpace(reqArr[i])) {
continue;
}
a.WriteLine(reqArr[i]);
} catch (ex:Exception) {
}
}
a.Close();
reqArr = new Array();
FiddlerObject.alert("保存成功");
}
如果想要将结果数据保存到csv文件中,供Jmeter使用,这里可能出现的问题是,csv文件是采用逗号分隔,如果需要写入文件中的数据有逗号,可能需要采用以下方式处理:
如果字段中有逗号(,),该字段使用双引号(")括起来;
如果该字段中有双引号,该双引号前要再加一个双引号,然后把该字段使用双引号括起来。
var reqHeaderArr = new Array();
reqArr[reqArr.length] = "XXX"; //// 这里注意length是小写
var sInput = '{}';
var oJSON = Fiddler.WebFormats.JSON.JsonDecode(sInput);
oJSON.JSONObject["USER"] = oSession.oRequest.headers["USER"];
oJSON.JSONObject["POST"] = oSession.oRequest.headers["POST"];
var result = Fiddler.WebFormats.JSON.JsonEncode(oJSON.JSONObject);
可以像C#一样import System相关包,但是JScript里面不能用List只能用ArrayList,备一些代码以后可能用得到
object[] objBytes = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
byte[] bytes = new byte[objBytes.Length];
for (int i = 0; i < objBytes.Length; i++)
{
bytes[i] = Convert.ToByte(objBytes[i]);
}