可以使用aardio轻松拦截并修改原生js或jqery所发送的ajax请求,
从而达到获取请求内容或应答内容的目的,
至于应用在什么场景,
想必肚子里有点坏水的朋友都想到了.
部分相关源码如下:
//方法1
//在http://www.jq22.com/cdn/下载JQ源码保存http://libs.baidu.com/jquery/2.0.0/jquery.min.js
//先注入JQ
var jqStr = string.load("C:\Users\Administrator\Desktop\jquery.min.js")
wb.doScript(jqStr)
//再使用JQ发送ajax请求
var jsStr = /*
$.post("http://jianma123.com/login.aardio","email=3424399322888%40qq.com&password=0000000",function(data,status){
//alert("JQ发送ajax获取到返回Data: " + data.substring(0,100) + "nStatus: " + status);
});
*/
wb.doScript(jsStr)
//方法2:也可以直接把JQ源码和调用jq发送ajax的代码放到一个文件里加载执行
//var jsStr = string.load("C:\Users\Administrator\Desktop\jq-ajax-post.txt")
//wb.doScript(jsStr)
//拦截原生JS发送ajax后的回调
onreadystatechange:function(xhr){
console.log("ajax有响应了 onreadystatechange called: %O",xhr)
if (xhr.readyState ==4 && xhr.status ==200){
alert("拦截到原生js发送ajax后得到的应答内容"+xhr.responseText.substring(0,100)+" ......");//应答的html内容;str.substring()截取字符串
external.aarfun1(xhr.responseText)//js中调用aarfun1输出
}
},
//拦截jQuery发送ajax后的回调
onload:function(xhr){
if (xhr.readyState ==4 && xhr.status ==200){
alert("拦截到jQuery发送ajax后得到的应答内容"+xhr.responseText.substring(0,100)+" ......");//应答的html内容;str.substring()截取字符串
external.aarfun2(xhr.responseText)//js中调用aarfun1输出
}
},
//拦截方法
open:function(arg,xhr){
//console.log("ajax被原生js或jQuery调用了 open called: method:%s,url:%s,async:%s",arg[0],arg[1],arg[2])
}