2015-09-17 171 views
0

如何從fiddler核心獲取img src屬性?我想獲得藍色從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

看起來就像是請求標題。你也許可以用類似檢查中BeforeRequest

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

BeforeResponse你可以得到圖像的完整URL。

var url = oS.fullUrl;