如何获取 HTTP POST 数据类型?

How to get type of HTTP POST data?

在上图中,我有 Request BodyPOST 请求 FiddlerCore dll

以下是我如何捕捉它:

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

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

但是,我只需要在它的参数(图片最后一行)的情况下捕获它,而在其他情况下我不需要捕获它。

我可以用 string 过滤它,这是我目前所做的。但是,这样做的正确方法是什么?

注意:图片上的每一行都是一个不同的请求,一共5个。

如果没有内容类型则忽略它。弄清楚你想要的那些并接受它们。

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.
}