发布时间:2022-07-14 15:03:54编辑:文明阅读(1726)
static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}
// if (oSession.fullUrl.Contains("baidu.com")){
if (1){
oSession.utilDecodeResponse();//消除保存的请求可能存在乱码的情况
var jsonString = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(jsonString);
if(oSession.fullUrl.Contains("api.bigfun.cn")&&(responseJSON.JSONObject=='System.Collections.ArrayList' || responseJSON.JSONObject=='System.Collections.Hashtable')&&jsonString!='[]'&&jsonString!='{}'){
// 判断是否是json数据 然后保存
var str='{}';//构造自己的JSON http请求的信息及返回的结果
var data = Fiddler.WebFormats.JSON.JsonDecode(str);
data.JSONObject["request_method"] = oSession.RequestMethod;
var requestString = oSession.GetRequestBodyAsString();
data.JSONObject["request_body"]= requestString;
data.JSONObject["response_data"] = responseJSON.JSONObject;
data.JSONObject["url"] = oSession.fullUrl;
data.JSONObject["response_code"] = oSession.responseCode;
jsonString = Fiddler.WebFormats.JSON.JsonEncode(data.JSONObject)
// 保存文件到本地
var fso;
var file;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.OpenTextFile("D:\\wow.txt",8 ,true, true);
file.writeLine("jsonData:"+jsonString);
file.writeLine("\n");
file.close();
// 数据通过post请求发送自己的后台服务保存
FiddlerObject.log('2222222222222222'+jsonString);
// methods
var method = "POST";
var myUrl = 'http://192.168.39.101:9909/api/v1/wa/save-fiddler-data'
var url = myUrl+'?data='+Utilities.UrlEncode(jsonString);
var protocol = "HTTP/1.1";
var raw="";
var selected: Session = oSession;
raw += method + " " + url + " " + protocol + "\r\n";
raw +="Host:192.168.39.101:9909\r\n";
raw +="Connection: keep-alive\r\n";
raw +="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n";
raw +="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36\r\n";
raw +="Accept-Encoding: gzip,deflate,sdch\r\n";
raw +="Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4\r\n";
raw +="Content-Type: application/json\r\n";
var body= "jsondata=''";
raw += "\r\n" + body;
FiddlerObject.utilIssueRequest(raw);
}
}
}
关键字:fiddler
7
4
4
2
2