从fiddler核心获取img src属性

时间:2015-09-17 06:19:03

标签: fiddlercore

如何从fiddler核心获取img src属性?我想获得以蓝色突出显示的值

enter image description here

                Fiddler.FiddlerApplication.BeforeRequest += delegate (Fiddler.Session oS) {
                //Console.WriteLine("Before request for:\t" + oS.fullUrl);
                    Console.WriteLine(oS.oRequest.headers.RequestPath.ToString());
                // In order to enable response tampering, buffering mode must
                // be enabled; this allows FiddlerCore to permit modification of
                // the response in the BeforeResponse handler rather than streaming
                // the response to the client as the response comes in.

                if ((oS.responseCode == 200) && oS.oResponse.headers.ExistsAndContains("Content-Type", "image/"))
                {
                    //Console.WriteLine("giving url");
                    //Console.WriteLine(oS.GetRedirectTargetURL());
                }//oS.bBufferResponse = true;
            };

            Fiddler.FiddlerApplication.BeforeResponse += delegate (Fiddler.Session oS) {
                if ((oS.responseCode == 200) && oS.oResponse.headers.ExistsAndContains("Content-Type", "image/"))
                {
                    oS.utilDecodeResponse();
                    //Console.WriteLine("writing bytes");
                    //Console.WriteLine(oS.GetRedirectTargetURL());

                    //Console.WriteLine(oS.responseBodyBytes.ToString());
                    // oS.responseBodyBytes is a byte[] containing the image
                    //Image img = Image.FromStream(new MemoryStream(oS.requestBodyBytes));
                    //Bitmap oBMP = new Bitmap(new MemoryStream(oS.responseBodyBytes));

                    //Console.WriteLine("{0}:HTTP {1} for {2}", oS.id, oS.responseCode, oS.fullUrl);
                    // Now oBMP is an image object which contains the picture...
                }

                // Uncomment the following two statements to decompress/unchunk the
                // HTTP response and subsequently modify any HTTP responses to replace 
                // instances of the word "Microsoft" with "Bayden"
                //oS.utilDecodeResponse(); oS.utilReplaceInResponse("Microsoft", "Bayden");
                //Console.WriteLine("\n");
                //Console.WriteLine("fininihs");

            };

            Fiddler.FiddlerApplication.AfterSessionComplete += delegate (Fiddler.Session oS) { //Console.WriteLine("Finished session:\t" + oS.fullUrl);
                if ((oS.responseCode == 200) && oS.oResponse.headers.ExistsAndContains("Content-Type", "image/"))
                {
                    //Console.WriteLine("giving url");
                    //Console.WriteLine(oS.GetRedirectTargetURL());
                }
            };

我必须在哪部分放置代码? BeforeRequest? BeforeResponse?还是AfterSession?

1 个答案:

答案 0 :(得分:1)

看起来那将是请求标头。您可以在BeforeRequest中使用以下内容进行检查:

var src = oS.oRequest.headers.Exists("src") ? oS.oRequest.headers["src"] : "",

BeforeResponse中,您可以获得图片的完整网址。

var url = oS.fullUrl;