To make custom changes to web requests and responses, use FiddlerScript to add rules to Fiddler's OnBeforeRequest or OnBeforeResponse function. Which function is appropriate depends on the objects your code uses: OnBeforeRequest is called before each request, and OnBeforeResponse is called before each response. Note:

  • It is not possible to access the response objects inside OnBeforeRequest as they have not yet been created.
  • It is possible to use objects from the request inside OnBeforeResponse; however, any changes you make to those objects will not be seen by the server, as it has already received the request.

Add a request header

    oSession.oRequest["NewHeaderName"] = "New header value";

Delete a response header

    oSession.oResponse.headers.Remove("Set-Cookie");

Change a request for one page to a different page on the same server

    if (oSession.PathAndQuery=="/version1.css") {
oSession.PathAndQuery="/version2.css";
}

Point all requests for one server to the same port on a different server

    if (oSession.HostnameIs("www.bayden.com")) {
oSession.hostname="test.bayden.com";
}

Point all requests for one port to a different port on a different server

    if (oSession.host=="www.bayden.com:8080") {
oSession.host="test.bayden.com:9090";
}

Point all requests for one server to a different server, including HTTPS tunnels

    // Redirect traffic, including HTTPS tunnels
if (oSession.HTTPMethodIs("CONNECT") && (oSession.PathAndQuery == "www.example.com:443")) {
oSession.PathAndQuery = "beta.example.com:443";
} if (oSession.HostnameIs("www.example.com")) oSession.hostname = "beta.example.com";

Simulate the Windows HOSTS file, by pointing one Hostname to a different IP address. (Retargets without changing the request's Host header)

    // All requests for subdomain.example.com should be directed to the development server at 128.123.133.123
if (oSession.HostnameIs("subdomain.example.com")){
oSession.bypassGateway = true; // Prevent this request from going through an upstream proxy
oSession["x-overrideHost"] = "128.123.133.123"; // DNS name or IP address of target server
}

Retarget requests for a single page to a different page, potentially on a different server. (Retargets by changing the request's Host header)

    if (oSession.url=="www.example.com/live.js") {
oSession.url = "dev.example.com/workinprogress.js";
}

Prevent upload of HTTP Cookies

    oSession.oRequest.headers.Remove("Cookie");

Decompress and unchunk a HTTP response, updating headers if needed

    // Remove any compression or chunking from the response in order to make it easier to manipulate
oSession.utilDecodeResponse();

Search and replace in HTML.

    if (oSession.HostnameIs("www.bayden.com") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('<b>','<u>');
}

Case insensitive Search of response HTML.

    if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "text/html") && oSession.utilFindInResponse("searchfor", false)>-1){
oSession["ui-color"] = "red";
}

Remove all DIV tags (and content inside the DIV tag)

    // If content-type is HTML, then remove all DIV tags
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes); // Replace all instances of the DIV tag with an empty string
var oRegEx = /<div[^>]*>(.*?)<\/div>/gi;
oBody = oBody.replace(oRegEx, ""); // Set the response body to the div-less string
oSession.utilSetResponseBody(oBody);
}

Pretend your browser is the GoogleBot webcrawler

    oSession.oRequest["User-Agent"]="Googlebot/2.X (+http://www.googlebot.com/bot.html)";

Request Hebrew content

    oSession.oRequest["Accept-Language"]="he";

Deny .CSS requests

    if (oSession.uriContains(".css")){
oSession["ui-color"]="orange";
oSession["ui-bold"]="true";
oSession.oRequest.FailSession(404, "Blocked", "Fiddler blocked CSS file");
}

Simulate HTTP Basic authentication (Requires user to enter a password before displaying web content.)

    if ((oSession.HostnameIs("www.example.com")) &&
!oSession.oRequest.headers.Exists("Authorization"))
{
// Prevent IE's "Friendly Errors Messages" from hiding the error message by making response body longer than 512 chars.
var oBody = "<html><body>[Fiddler] Authentication Required.<BR>".PadRight(512, ' ') + "</body></html>";
oSession.utilSetResponseBody(oBody);
// Build up the headers
oSession.oResponse.headers.HTTPResponseCode = 401;
oSession.oResponse.headers.HTTPResponseStatus = "401 Auth Required";
oSession.oResponse["WWW-Authenticate"] = "Basic realm=\"Fiddler (just hit Ok)\"";
oResponse.headers.Add("Content-Type", "text/html");
}

Respond to a request with a file loaded from the \Captures\Responses folder (Can be placed in OnBeforeRequest or OnBeforeResponse function)

    if (oSession.PathAndQuery=="/version1.css") {
oSession["x-replywithfile"] ="version2.css";
}

Modifying a Request or Response的更多相关文章

  1. Request 和 Response 原理

    * Request 和 Response 原理:     * request对象和response对象由服务器创建,我们只需要在service方法中使用这两个对象即可        * 继承体系结构: ...

  2. Request 、Response 与Server的使用

    纯属记录总结,以下图片都是来自 ASP.NET笔记之 Request .Response 与Server的使用 Request Response Server 关于Server.MapPath 方法看 ...

  3. request 和response

    当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为它让我们理解了We ...

  4. Request和Response对象

    Request 和 Response 对象起到了服务器与客户机之间的信息传递作用.Request 对象用于接收客户端浏览器提交的数据,而 Response 对象的功能则是将服务器端的数据发送到客户端浏 ...

  5. Java 中的 request 和response 理解

    request和response(请求和响应)  1.当Web容器收到客户端的发送过来http请求,会针对每一次请求,分别创建一个用于代表此次请求的HttpServletRequest对象(reque ...

  6. 【转】request和response的页面跳转传参

    下面是一位园友的文章: jsp或Servlet都会用到页面跳转,可以用 request.getRequestDispatcher("p3.jsp").forward(request ...

  7. LoadRunner中取Request、Response

    LoadRunner中取Request.Response LoadRunner两个“内置变量”: 1.REQUEST,用于提取完整的请求头信息. 2.RESPONSE,用于提取完整的响应头信息. 响应 ...

  8. Spring mvc中使用request和response

    @ResponseBody @RequestMapping(value="/ip", method=RequestMethod.GET) public String getIP(H ...

  9. springMVC获取request和response

    转载:http://blog.sina.com.cn/s/blog_7085382f0102v9jg.html 1.参数 例如: @RequestMapping("/test") ...

随机推荐

  1. 设置ubuntu 终端显示路径长度

    ~/.bashrc 这个文件记录了用户终端配置. 打开~/.bashrc 这个文件 $: sudo vim ~/.bashrc 找到 将蓝色的w由小写改成大写,可以表示只显示当前目录名称.

  2. offset大家族(一)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. git 忽略文件 .gitignore 以及规则

    git提供了文件忽略系统,当对工作区某个目录或文件设置了忽略后,在执行status查看状态时,被忽略的文件即使存在也不会显示出来. 这样我就可以把那些不需要上传,不需要保留的文件或目录忽略掉(比如一些 ...

  4. DataTable添加行的方法

    方法一: DataTable  tblDatas = new DataTable("Datas");DataColumn dc = null;dc = tblDatas.Colum ...

  5. 你得学会并且学得会的Socket编程基础知识(续)——Silverlight客户端

    本文将在这个案例的基础上,加入一个特殊场景,利用Silverlight来实现客户端.有的朋友可能会说,其实是一样的吧.请不要急于下结论,有用过Silverlight的朋友都有这种体会,很多在标准.NE ...

  6. 聊聊高并发(十四)理解Java中的管程,条件队列,Condition以及实现一个堵塞队列

    这篇里面有一些主要的概念,理解概念是件有意义的事情,仅仅有理解概念才干在面对详细问题的时候找到正确的解决思路.先看一下管程的概念 第一次在书上看到管程这个中文名称认为非常迷糊,管程究竟是个什么东东,于 ...

  7. ASP.NET Core 1.0基础之依赖注入

      来源https://docs.asp.net/en/latest/fundamentals/dependency-injection.html ASP.NET Core 1.0在设计上原生就支持和 ...

  8. python接口自动化4-绕过验证码登录(cookie)

    前言 有些登录的接口会有验证码:短信验证码,图形验证码等,这种登录的话验证码参数可以从后台获取的(或者查数据库最直接). 获取不到也没关系,可以通过添加cookie的方式绕过验证码. 一.抓登录coo ...

  9. 新手学习selenium路线图(老司机亲手绘制)-学前篇

    前言: 本来这篇是只在微信公众号(yoyoketang)上发布的,最近一搜,发现本很多人copy(copy公众号的,图片是加载不出来的)了,还没注明出处,不想多说什么,博客上也同步更新这篇吧! 最近群 ...

  10. 页面中checkbox返回的是一个数组,如何对数组进行操作

    1. 仅仅利用javascript进行操作: //html代码如下: <form action="#" method="POST" onsubmit=&q ...