前两天因项目须要,简单看了一下FiddlerScript,功能挺强的。今天有时间细致看一下,做个笔记。

改动Request或Response

改动Request和Response要在FiddlerScript中的OnBeforeRequest和OnBeforeResponse函数中加入规则就可以。OnBeforeRequest函数是在每次请求之前调用。OnBeforeResponse函数是在每次响应之前调用。

1、加入请求头Header

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

2、删除Response的Header

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

3、将请求从一个页面转发到同一Server上的还有一页面

if (oSession.PathAndQuery=="/hello/hello.html") {
oSession.PathAndQuery="/hello/index.html";
}

注意:oSession.PathAndQuery的值为fiddler中session列表中的Url:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY29vbGNhb3Nq/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">

即图中红色标注出来的部分。图中黄色标注出来的部分有点特殊。host为Tunnel to ,url为还有一host。

查看该请求的Header为:

这样的特殊情况会在以下还有样例。

上面的样例,拦截请求地址为/hello/hello.html的请求,并将其转发到同样Server的/hello/index.html

4、将请求转发到同样port号的不同server(改动请求的Host)

if(oSession.HostnameIs("www.baidu.com")){
oSession.hostname = "www.sina.com.cn";
}


这个样例是将发送到百度的请求转发到新浪。则会提示页面不存在。

这里仅仅是改变了host,并不改变后面的地址。因此。假设在新浪上不存在对应的页面。如以下图片所看到的:

假设我訪问的是例如以下地址:http://www.baidu.com/link?url=CQuVpjo9u9UQADcstwECPEmrziPMk5u5H9PlRN2TbWLkKZaxafVER2X8OEYzovr-yasX2Fwcgj0NANBtKVj0gN78jNJ3bXTmIsTeBk7hXem

则结果例如以下:(该页面实际是存在的,是百度搜索出来的结果页面,被fiddler转发到新浪。可是新浪上不存的此页面)

5、将请求转发到不同port号,不同Server

    if (oSession.host=="192.168.0.70:8080") {
oSession.host="192.168.0.69:8020";
}

这个样例是将发送到192.168.0.70:8080的请求转发到192.168.0.69:8020,这里仅仅是改变host。并不改变后面的请求地址。比如,做以上的规则后。我请求的是:

http://192.168.0.70:8080/hello/hello.html

而实际我项目部署到的是:192.168.0.69:8020

6、将全部请求从一个server转发到还有一个server,包含Https

    // 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";

7、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
}

8、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";
}

9、Prevent upload of HTTP Cookies

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

10、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();

11、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>');
}

12、Case insensitive Search of response HTML.

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

13、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);
}

14、Pretend your browser is the GoogleBot webcrawler

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

15、Request Hebrew content

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

16、Deny .CSS requests

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

17、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");
}

18、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";
}

以上样例我并没有都实践。仅仅实践了中间几个地址转发的,由于如今须要用。剩下的请大家有须要的自己实践吧。

FiddlerScript学习一:改动Request或Response的更多相关文章

  1. JavaWeb学习笔记四 request&response

    HttpServletResponse 我们在创建Servlet时会覆盖service()方法,或doGet()/doPost(),这些方法都有两个参数,一个为代表请求的request和代表响应res ...

  2. 转 #HTTP协议学习# (一)request 和response 解析

    http://www.cnblogs.com/bukudekong/p/3834020.html #HTTP协议学习# (一)request 和response 解析   注:本文转自:http:// ...

  3. #HTTP协议学习# (一)request 和response 解析

    注:本文转自:http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html , 粉字[]内内容为个人笔记 当今web程序的开发技术真是 ...

  4. JavaWeb学习总结(三)response与request

    一.response response是Servlet.service方法的一个参数,类型为javax.servlet.http.HttpServletResponse.在客户端发出每个请求时,服务器 ...

  5. Java web课程学习之Request和Response

    request和response l HttpServletRequest l 请求转发 l HttpServletResponse l 请求重定向   请求流程 每次请求service(),都会由容 ...

  6. Web jsp开发学习——终极解决jsp中request和response中文乱码的问题(加个过滤器)

    中文乱码真的很烦人的.而且每次都要写,可麻烦了,而且有时候写了还不一定管用,所以我们可以试试过滤器 1.每个jsp头上当然要写上utf8啦 <%@ page language="jav ...

  7. javaweb学习总结二十五(response对象的用法一)

    一:Reponse对象的概念 当客户端发送http请求时,服务器端会对每一次请求,创建request对象和response对象. response对象包括三个部分:响应头.响应状态码以及响应体 二:r ...

  8. [Rails] 从 Request 到 Response(2)

    本文翻译自:Rails from Request to Response 系列:个人选择了自己感兴趣的部分进行翻译,需要阅读原文的同学请戳前面的链接. 第二部分 路由(Routing) Blog::A ...

  9. 关于request、response转发与重定向的简述

    在做页面的请求与响应的时候我们多用request与response进行操作,而我们大家也知道,request是表示用户发向服务器的请求,而response是对用户请求的一个响应. 关于转发和重定向,通 ...

随机推荐

  1. 【bzoj4281】[ONTAK2015]Związek Harcerstwa Bajtockiego 树上倍增+LCA

    题目描述 给定一棵有n个点的无根树,相邻的点之间的距离为1,一开始你位于m点.之后你将依次收到k个指令,每个指令包含两个整数d和t,你需要沿着最短路在t步之内(包含t步)走到d点,如果不能走到,则停在 ...

  2. Hive 01 概述、安装配置

    概述 数据仓库:是一个面向主题的.集成的.不可更新的.随时间不变化的数据集合,它用于支持企业或组织的决策分析处理. 数据仓库的结构和建立过程: 数据源 数据存储及管理 ETL Extract 提取 T ...

  3. linux编程学习

    linux编程学习 工具篇 “公欲善其事,必先利其器”.编程是一门实践性很强的工作,在你以后的学习或工作中,你将常常会与以下工具打交道, 下面列出学习 C 语言编程常常用到的软件和工具. (一)操作系 ...

  4. Codeforces Round #321 (Div. 2) C dfs处理(双向边叶子节点的判断)

    C. Kefa and Park time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. 分布式文件系统FastDFS集群部署

    1.源码开放下载地址:https://github.com/happyfish100 早期源码开放下载地址:https://sourceforge.net/projects/fastdfs/files ...

  6. mac 下 python 虚拟环境的安装和配置

    前言:继续安装中,这节记录 mac 安装 python 虚拟环境,多版本共存... 1. 安装 pip -- python的包管理工具: sudo easy_install pip 安装成功,出现下面 ...

  7. 转:Java 动态代理的内部实现机制(大体意思正确,写的还行的一篇文章)

    转:Java动态绑定的内部实现机制 JAVA虚拟机调用一个类方法时,它会基于对象引用的类型(通常在编译时可知)来选择所调用的方法.相反,当虚拟机调用一个实例方法时,它会基于对象实际 的类型(只能在运行 ...

  8. 【CF1015D】Walking Between Houses(构造,贪心)

    题意:从1开始走,最多走到n,走k步,总长度为n,不能停留在原地,不能走出1-n,问是否有一组方案,若有则输出 n<=1e9,k<=2e5,s<=1e18 思路:无解的情况分为两种: ...

  9. 怎样在SQL2005中设置 自增长类型?

    原文发布时间为:2009-04-25 -- 来源于本人的百度文章 [由搬家工具导入] 最近好几个人问我。。。。。 企业管理器-->右键你的表-->设计表-->选中一int类型字段-- ...

  10. jenkins 中 violation使用pylint

    在jenkins中无法打开源码问题: 1. 在 Report Violations的 Source encoding 设置为 项目文件的编码, 如: utf-8.  缺省是 default. 2. 在 ...