我正在尝试拦截响应并更改特定 url 的响应 html 正文。我能够更新 html 内容中的字符串,但是当我在浏览器中签入时,我无法找到我所做的更改。
我用它来改变响应
private void FiddlerApplication_BeforeResponse(Session oSession)
{
//if (!oSession.fullUrl.ToLower().Contains(txtCaptureUrl.Text.Trim().ToLower()))
// return;
if (oSession.fullUrl.ToLower().Contains("localhost"))
return;
//Search and replace in HTML.
if (oSession.fullUrl.ToLower().Contains("prohance"))
{
if (oSession.HostnameIs("10.10.10.199") && oSession.oResponse.headers.ExistsAndContains("Content-Type", "text/html"))
{
oSession.bBufferResponse = true;
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
//oBody = ReplaceFirst(oBody, "</script>", "<script type='text/javascript'>alert(123)</script>");
oBody = ReplaceFirst(oBody, "ATTENDANCE", "RAVIKANTH");
oSession.utilSetResponseBody(oBody);
oSession.utilDecodeResponse();
var oBody1 = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
}
return;
}
}
public string ReplaceFirst(string text, string search, string replace)
{
int pos = text.IndexOf(search);
if (pos < 0)
{
return text;
}
return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
}