http跨域设置
- 安装完之后菜单栏点击Rules,选择Customize Rules,在
OnBeforeResponse(oSession: Session) {
里面添加
oSession.responseCode=200;oSession.oResponse.headers.Add("Access-Control-Allow-Headers", "content-type,x-requested-with");oSession.oResponse.headers.Add("Access-Control-Allow-Origin","*");
完整代码段如下:
static function OnBeforeResponse(oSession: Session) { if (m_Hide304s && oSession.responseCode == 304) { oSession["ui-hide"] = "true"; } oSession.responseCode=200; oSession.oResponse.headers.Add("Access-Control-Allow-Headers", "content-type,x-requested-with"); oSession.oResponse.headers.Add("Access-Control-Allow-Origin","*"); }
完成之后保存就可以处理跨域请求了,目前只能处理http的强求,当请求协议是https时浏览器还会提示跨域,因为fiddler默认不支持抓取https的请求。
https跨域设置
- 菜单栏点击Tools,选择Options。
- 选择弹框菜单栏中的https项,勾选“CaptureHTTPS CONNECTs”,
- 同时勾选“Decrypt HTTPS traffic”,弹出的对话框选择是(这里是按照fiddler自己的证书),如果需要监听不可信的证书的HTTPS请求的话,需要勾选“Ignore servercertificate errors”。
fiddler4设置
- 在使用fiddler4的时候,完成上面几步之后https的请求还是会报错,如以下之类的问题: creation of the root certificate was not successful; Failed to find the root certificate in User Root List; The Root certificate could not be found; The root certificate could not be located;
- 点击 htpps里面的 Actions按钮选择Export Root certificate to Desktop;但是会报The root certificate could not be located的错
- 需要下载并安装Fiddler证书生成器:;(可能还需要墙一下)
- 重启fiddler,再重新点击 htpps里面的 Actions按钮选择Export Root certificate to Desktop;现在就可以了
- 可能之后还会出现打开网站提示https证书失效的情况,去掉 https里面的Capture HTTPS CONNECTS保存,去IE删除fiddler的证书,重新打开fiddler勾上刚才去掉的选项保存就好了,会提示安装证书,安装完之后就好了
PS:感谢大佬的文章,问了度娘好久才找到的,其它的都是千篇一律的匹配正则,匹配域名,换一个api就要重新去修改,这个只要改一次就OK了。