Search code examples
fiddlercore

Getting the img src property from fiddler core


How do i obtain the img src property from fiddler core? I would like to obtain the value highlighted in blue

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());
                }
            };

In which portion do i have to place my code? BeforeRequest? BeforeResponse? or AfterSession?


Solution

  • Looks like that would be the request header. You could probably check it in BeforeRequest with something like:

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

    In the BeforeResponse you can get the full url of the image.

    var url = oS.fullUrl;