2017-07-02 31 views
1

enter image description here如何獲取HTTP POST數據的類型?

在上圖中,我有一個POST請求與FiddlerCore dllRequest Body

這是我如何捕獲它:

private void FiddlerApplication_AfterSessionComplete(Session sess) 
{ 
     string requestBody = ""; 

     if (sess.oRequest != null) 
     { 
      if (sess.oRequest.headers != null) 
      { 
       requestBody = sess.GetRequestBodyAsString(); 
      } 
     } 
} 

不過,我只需要捕獲它在它的參數(圖片上的最後2行)的情況下,並在其他情況下,我並不需要捕捉它。

我可以使用string進行過濾,這是我迄今爲止所做的。但是,怎樣才能做到這一點呢?

注:上的圖像的每一行都是不同的請求,共計5

+0

我這麼認爲,對於第一個2我必須誠實,我不知道他們應該是什麼......但如果我對參數感興趣,我可以跳過它們嗎?我只是用Content-Type做了一個測試,似乎大部分我不想要的都不具備Content-Type屬性 – Cher

+0

有第一條線索。用它作爲過濾器。如果沒有內容類型,則忽略它。找出你想要的並拿走它們。什麼是您想要的內容類型 – Nkosi

+0

對於請求我必須捕獲每個POST請求。不過,我只顯示身體,如果他們是參數...現在查看屬性,我看不到任何唯一標識我需要保留的請求... – Cher

回答

1

如果沒有內容類型,則忽略它。找出你想要的並拿走它們。

private void FiddlerApplication_AfterSessionComplete(Session sess) { 
    if (sess == null || sess.oRequest == null || sess.oRequest.headers == null) 
     return; 

    // Ignore HTTPS connect requests or other non-POST requests 
    if (sess.RequestMethod == "CONNECT" || sess.RequestMethod != "POST") 
     return; 

    var reqHeaders = sess.oRequest.headers.ToString(); //request headers 

    // Get the content type of the request 
    var contentType = sess.oRequest["Content-Type"]; 

    // Lets assume you have a List<string> of approved content types. 

    // Ignore requests that do not have a content type 
    // or are not in the approved list of types. 
    if(contentType != null && !approvedContent.Any(c => contentType.Containes(c)) 
     return;  

    var reqBody = sess.GetRequestBodyAsString();//get the Body of the request 

    //...other code. 
} 
+0

謝謝!!我剛纔看到,我想要的所有那些至少包含image/gif!非常感謝!!! – Cher