0
点赞
收藏
分享

微信扫一扫

Fiddler oS.utilSetResponseBody无效问题

其生 2023-01-16 阅读 89


在使用FiddlerCore时,在onBeforeRequest中想对所有请求返回111

public void onBeforeRequest(Fiddler.Session oS)
{
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers.SetStatus(200, "Ok");
oS.oResponse["Content-Type"] = "text/html; charset=UTF-8";
oS.oResponse["Cache-Control"] = "private, max-age=0";
oS.utilSetResponseBody("<html><body>111</body></html>");
}

在打开网页 ​​https://cn.bing.com/​​ 时,发现浏览器提示错误:网页无法访问

加上日志后,发现https先访问的地址是:onBeforeRequest: http://cn.bing.com:443 

难道不能拦截443?

代码改成:

public void onBeforeRequest(Fiddler.Session oS)
{
// In order to enable response tampering, buffering mode MUST
// be enabled; this allows FiddlerCore to permit modification of
// the response in the BeforeResponse handler rather than streaming
// the response to the client as the response comes in.
//oS.bBufferResponse = true;

LogHelper.showLog("onBeforeRequest: " + oS.fullUrl);

if(oS.fullUrl.IndexOf("443") < 0)
{
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers.SetStatus(200, "Ok");
oS.oResponse["Content-Type"] = "text/html; charset=UTF-8";
oS.oResponse["Cache-Control"] = "private, max-age=0";
oS.utilSetResponseBody("<html><body>111</body></html>");
}
}

放行443后,一切正常,符合预期需求了。。。

 

举报

相关推荐

0 条评论