I am trying to intercept the response and alter the response html body of the specific url. i am able to update the string in the html content but when i check in browser i am not able to find the changes i made.
i am using this for altering the response
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);
}
when i am debugging i am see the response has been modified but when i check in browse i am not able to see the desired result what may be the problem