做过测试的应该都知道Fiddler,它可以很方便截取Internet上的网页替换成本地的,或者修改其中的一部分内容后呈现。简单地说就是可能监测所有HTTP连接,设置断点,胡乱修改。是测试调试的一件利器。
使用Fiddler的开放组件,我们可以将其集成到自己的程序中,如生成flash/silverlight所需要的crossdomain.xml,clientaccesspolicy.xml安全文件等:
Fiddler的API: http://www.fiddler2.com/fiddler/dev/ScriptSamples.asp

下面是一个小例子:自动生成所有的silverlight安全策略文件:

using System;
using Fiddler;

namespace AccessPolicyTool
{
    class Program
    {
        const string PolicyXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<access-policy>
    <cross-domain-access>
        <policy>
            <allow-from http-request-headers=""*"">
                <domain uri=""http://*""/>
            </allow-from>
            <grant-to>
                <resource path=""/"" include-subpaths=""true""/>
            </grant-to>
        </policy>
    </cross-domain-access>
</access-policy>";

//find and replace the client access policy file.
        static void Main(string[] args)
        {
            //List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>();

Fiddler.FiddlerApplication.BeforeRequest += new SessionStateHandler(FiddlerApplication_BeforeRequest);
            Fiddler.FiddlerApplication.BeforeResponse += new Fiddler.SessionStateHandler(FiddlerApplication_BeforeResponse);

Fiddler.FiddlerApplication.Startup(8877, FiddlerCoreStartupFlags.Default);
            Console.ReadKey();
            Fiddler.FiddlerApplication.Shutdown();
        }

static void FiddlerApplication_BeforeRequest(Session oSession)
        {
            Console.WriteLine("FiddlerApplication_BeforeRequest");

if (oSession.fullUrl.IndexOf("clientaccesspolicy.xml") > 0)
            {
                oSession.bBufferResponse = true;
            }
        }

//find and replace the client access policy file.
        static void FiddlerApplication_BeforeResponse(Fiddler.Session oSession)
        {
            if (oSession.fullUrl.IndexOf("clientaccesspolicy.xml") > 0)
            {
                Console.WriteLine(oSession.fullUrl);

oSession.utilDecodeResponse();
                oSession.utilSetResponseBody(PolicyXml);

oSession.oResponse.headers.HTTPResponseCode = 200;
                oSession.oResponse.headers.HTTPResponseStatus = "200 OK";
                oSession.oResponse.headers["Content-Type"] = "text/xml";
                oSession.oResponse.headers.Remove("WWW-Authenticate");
            }
        }
    }
}

FiddlerCore 修改HTTP返回结果

发了封邮件给官网,问题解决了。 
在BeforeRequest事件中设置Session.bBufferResponse = true 就可以了。

使用FiddlerCore来截取替换Http请求中的网页内容的更多相关文章

  1. asp.net 字符串替换、截取和从字符串中最后某个字符 开始截取

    有时候要在一段字符串里面把某些字符替换成其他字符,怎么办? 例如: string image=@"csks/news/user_top/qqqq/qqqq.jpg"; image ...

  2. 【原创】http请求中加号被替换为空格?源码背后的秘密

    这是why技术的第**20**篇原创文章![在这里插入图片描述](https://user-gold-cdn.xitu.io/2019/12/30/16f550eb82e10eff?w=900& ...

  3. 在ajax请求中,contentType 和 dataType 的区别?

    一.在ajax请求中,contentType 和 dataType 的区别? 1.contentType 内容类型. 1.1默认是 "application/x-www-form-urlen ...

  4. 用Retrofit发送请求中添加身份验证

    用Retrofit发送请求中添加身份验证====================在安卓应用开发中, retrofit可以极大的方便发送http网络请求,不管是GET, POST, 还是PUT, DEL ...

  5. AGS中通过FeatureServer插入数据失败、插入数据在WMTS请求中无法显示以及version概念的讨论

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 在多个项目中,当我方接口给其他部门人员使用时出现了插入数据失 ...

  6. 在基于vue的webpack脚手架开发中使用了代理转发,结果浏览器发出的请求中不带cookie导致登录时总是session失效怎么办?

    环境:            有2个业务接口需要转发到82的服务器上:     ../user/getCode.do     ../user/doLogin.do 现象:          使用上述的 ...

  7. Http请求中Content-Type讲解以及在Spring MVC中的应用

    引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...

  8. Angularjs之如何在跨域请求中传输Cookie

    一般情况我们在使用WebApi之类的技术时,都会遇到跨域的问题,这个只需要在服务端做一下处理即可. 如果这些GET或POST请求不需要传递Cookie数据的话,就没什么问题了,但如果需要,那么会发现 ...

  9. HTTP协议---HTTP请求中的常用请求字段和HTTP的响应状态码及响应头

    http://blog.csdn.net/qxs965266509/article/details/8082810 用于HTTP请求中的常用请求头字段 Accept:用于高速服务器,客户机支持的数据类 ...

随机推荐

  1. sql语句 case

    case: SELECT stdname, max( CASE WHEN stdsubject = '语文' THEN result ELSE 0 END) "语文", max( ...

  2. JAVA识别字符串是数字(英文)还是汉字,web页面进行字符截断的帮助类

    public static void main(String[] args) { //长度是2说明是英文/数字/英文状态下的字符,长度为4说明是汉字/中文状态下的字符 String str = &qu ...

  3. django之创建第4-2个项目-访问class类属性和类方法

    1.修改index <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  4. Linux人工清理内存cache

     内存缓存的出现是解决,设备之间的读写速度的差异! 00.linux缓存解释 /proc/sys/vm/drop_caches (since Linux 2.6.16)Writing to this ...

  5. Docker 技巧:删除 Docker 所有镜像

    删除所有未运行 Docker 容器 docker rm $(docker ps -a -q) 删除所有 Docker 镜像 删除所有未打 tag 的镜像 docker rmi $(docker ima ...

  6. 【LeetCode】216. Combination Sum III

    Combination Sum III Find all possible combinations of k numbers that add up to a number n, given tha ...

  7. lsof命令详解(转)

    lsof命令详解(转) 上一篇 / 下一篇  2011-06-09 21:56:41 / 个人分类:Linux 查看( 351 ) / 评论( 0 ) / 评分( 0 / 0 ) 在Linux中,ls ...

  8. 怎么卸载用 make install 编译(源码)安装的软件?

    在linux 中用 ./configure && make && make install 后,如果想删除这个软件我应该怎么删除呢?好像有一个叫"make u ...

  9. [转]expect实现ssh自动交互

    shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:&quo ...

  10. 【Spring】SpringMVC之拦截器

    Spring的HandlerMapping处理器支持拦截器应用.当需要为某些请求提供特殊功能时,例如实现对用户进行身份认证.登录检查等功能. 拦截器必须实现HandlerInterceptor接口,实 ...