专注咖啡相关的网站,衡水网站设计费用,永嘉网站开发公司,腾讯企业邮箱免费登录入口windows下安装AnyProxy抓取移动App Http请求AnyProxy是阿里巴巴基于 Node.js 开发的一款开源代理服务器。做为中间代理服务器#xff0c;它可以收集所有经过它的http请求流量#xff08;包括https明文内容#xff09;#xff1b;它提供了友好的web界面#xff0c;便于直观… windows下安装AnyProxy抓取移动App Http请求 AnyProxy是阿里巴巴基于 Node.js 开发的一款开源代理服务器。做为中间代理服务器它可以收集所有经过它的http请求流量包括https明文内容它提供了友好的web界面便于直观的查看经过它的http请求同时它支持二次开发可以用javascript控制整个代理的全部流程便于前端调试和收集http请求页面内容。它可以用于移动app和移动web页面调试、 抓取。 一、实验环境操作系统 Windows 10 X64位 AnyPorxy版本 3.10.4 二、安装Node.js 从Node.js官网 官网下载最新版或者稳定版Node.js的msi文件后双击安装知道安装完成即可 三、安装和启动AnyProxy 、安装AnyProxy 安装好Node.js后在windows的命令提示符中输下面命令安装AnyProxy耐心等待直到安装完成 npm install -g anyproxy 2、生成根证书RootCA https需要证书才能以明文的方式显示请求内容所有这里我们必须生成根证书。在cmd命令提示符中运行下面命令生成根证书 anyproxy --root 3、启动AnyProxy代理监听服务 通过”anyproxy -i“命令启动代理监听其中”-i“参数启用https请求内容解析。 anyproxy -i 通过上面命令启动AnyProxy代理监听服务服务后AnyProxy会打开两个端口 * 8001端口即代理服务端口 本机的IP和8001用于设置代理如192.168.0.119:8001 * 8002端口AnyProxy的web界面通过浏览器打开http://192.168.0.119:8002的形式即可查看所有经过AnyProxy代理的http请求。 四、设置代理手机端 1、安装证书 我们需要在被代理的手机上安装证书这样在AnyProxy上才能以明文的方式查看https请求内容。在手机上安装证书有两种方式 1. 直接在手机浏览器中打开http://ip:8002/fetchCrtFileIP换成安装AnyProxy机器的IP 2. 在安装AnyProxy主机上打开”http://localhost:8002/qr_root“然后用微信 扫描二维码再通过微信在浏览器中打开的方式安装证书必须在微信中跳转到浏览器中打开否则弹不出安装证书对话框。 、设置代理以ios举例 在手机wifi设置中手动设置http代理在服务器中输入安装上面的代理IP端口输入8001保存即可。这样在此手机上所有的http请求包括Web站点和收集app如微信中的http请求都会通过AnyProxy代理。在安装AnyProxy的电脑上打开”http://localhost:8002”即可看到所有被代理的http请求。 5二次开发 1获取相关文档 github上下载anyproxy开发代码样例 https://github.com/alibaba/anyproxy 下载开发文档 http://anyproxy.io/4.x/ 2阅读anyproxy开发样例代码 The following are sample rules.* rule__blank.js* blank rule file with some comments. You may read this before writing your own rule file.* 空白的规则文件模板和一些注释
* rule_adjust_response_time.js* delay all the response for 1500ms* 把所有的响应延迟1500毫秒
* rule_allow_CORS.js* add CORS headers to allow cross-domain ajax request* 为ajax请求增加跨域头
* rule_intercept_some_https_requests.js* intercept https requests toward github.com and append some data* 截获github.com的https请求再在最后加点文字
* rule_remove_cache_header.js* remove all cache-related headers from server* 去除响应头里缓存相关的头
* rule_replace_request_option.js* replace request parameters before sending to the server* 在请求发送到服务端前对参数做一些调整
* rule_replace_response_data.js* modify response data* 修改响应数据
* rule_replace_response_status_code.js* replace servers status code* 改变服务端响应的http状态码
* rule_reverse_proxy.js* assign a specific ip address for request* 为请求绑定目标ip
* rule_use_local_data.js* map some requests to local file* 把图片响应映射到本地 View Code * rule_replace_response_data.js * modify response data * 修改响应数据 以此为例开发属于自己的js 3开发js 1,新建一js文件参考rule_replace_response_data.js添加逻辑获取想要的信息。 下面附上简单的simple.js实现将服务端返回的数据保存到本地文件中。 1 var fs require(fs);2 var locallist anyproxy_data/test.txt; //提前在本代码路径下新建anyproxy_datawen文件夹3 module.exports {4 // 功能描述5 summary: function() {6 return get data from ***;7 },8 replaceServerResDataAsync: function(req,res,serverResData,callback){9 // 匹配接口将返回的数据写入anyproxy_data/locallist.txt下
10 if (req.url.indexOf(/html/i.test) 0) {
11 var newDataStr serverResData.toString();
12 fs.appendFile(locallist, newDataStr \n, utf8, function(err) {
13 if(err) {
14 console.log(err);
15 }
16 })
17 callback(newDataStr);
18 }
19 else{
20 callback(serverResData);
21 }
22 }
23 }; 4运行 anyproxy --rule ./rule_sample/simple.js (rule后面是js的路径) anyproxy -i --rule ./rule_sample/simple.js (rule后面是js的路径-i是监听https请求) 5验证 在手机上发送simple中要求匹配的路径请求查看anyproxy_data文件夹下面是否都txt文件产生 转载于:https://www.cnblogs.com/youzi-zaitaxiang/p/7390437.html