1、在Fiddler 的 FiddlerScript 中进行编辑
2、在OnBeforeRequest中插入代码,
//这里其实我们的项目是分为不同的传输方式的,所以有两种判断,根据自己的情况来定 if (oSession.fullUrl.Contains("appUri")){ var fso; var file; fso = new ActiveXObject("Scripting.FileSystemObject"); //文件保存路径,可自定义 file = fso.OpenTextFile("C:\\Users\\user\\Desktop\\test.txt",8 ,true,true); //这里其实有好多方法,获取不同的数据,可以点击右上角的ClassView进行查看 //row["data"] = oSession.GetRequestBodyAsString(); //row["data"] = oSession.requestBodyBytes; //row["data"] = oSession.WriteRequestToStream; //这里需要特别注意一下,导出的byte[]数组值范围是0~255,不是java中的-128~127,如果需要请看文章底部 var array = new Array("postenc",oSession.url, oSession.requestBodyBytes); //file.writeLine("{\"flag\":\""+ row["flag"] + "\",\"url\":\""+row["url"] +"\",\"data\":\""+row["data"]+"\"}"); //这里为了方便,我就把所有的数据加到了数组中,然后用join方法,写到一行了,为了自动化脚本,根据自己情况定 file.writeLine(array.join("---------")); /*file.writeLine("Request header:" + "\n" + oSession.oRequest.headers.HTTPMethod); file.writeLine("flag: postenc"); file.writeLine("Request url: " + oSession.url); file.writeLine("Request body: " + oSession.GetRequestBodyAsString()); file.writeLine("\n");*/ file.close(); } else if (oSession.fullUrl.Contains("Uri1")||oSession.fullUrl.Contains("Uri2")||oSession.fullUrl.Contains("Uri3")){ var fso; var file; fso = new ActiveXObject("Scripting.FileSystemObject"); //文件保存路径,可自定义 file = fso.OpenTextFile("C:\\Users\\user\\Desktop\\test.txt",8 ,true,true); if(oSession.oRequest.headers.HTTPMethod.Equals("POST") || oSession.oRequest.headers.HTTPMethod.Equals("GET")){ //row["flag"] =oSession.oRequest.headers.HTTPMethod; //row["url"] = oSession.url; //row["data"] = oSession.GetRequestBodyAsString(); var array = new Array(oSession.oRequest.headers.HTTPMethod,oSession.url, oSession.GetRequestBodyAsString()); file.writeLine(array.join("---------")); /*file.writeLine("Request url: " + oSession.url); file.writeLine("Request body: " + oSession.GetRequestBodyAsString()); file.writeLine("\n");*/ } file.close(); }
java中数组和C#中数组进行转化
//这里的encString转换过程 C#Byte[]----》String----》String[] String[] encString = a[2].split(","); int[] encInt = new int[encString.length]; byte[] encBytes = new byte[encString.length]; for (int i=0;i<encString.length;i++){ //C#的byte[]数组是0~255,java的byte[]数组是-128~127,之间需要进行转换 //然后将String[]---》int[]----》Byte[](java中的) encInt[i] = Integer.parseInt(encString[i]); encBytes[i] = (byte) (encInt[i]&0xff); }