Skip to content

Unable to get PostData from IRequest #4783

Description

@aiqinxuancai

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

CefSharp Version

123.0.60

Operating System

Windows 10

Architecture

x64

.Net Version

.Net8.0

Implementation

WPF

Reproduction Steps

I have a program embedded with CefSharp, which I use to intercept some POST requests and process them. It has been working well for a long time, but recently it seems that the website has been updated. Without any updates or changes to my program, I am unable to retrieve the data from IRequest's PostData.
This is somewhat strange, as not all PostData cannot be retrieved, only a specific frame request on this website. In the debugging interface, I can see the FormData submitted by the request, but in the code, I cannot retrieve the PostData.

I tried testing with the simplest code possible, and the result was the same.

public class CustomRequestHandler : RequestHandler
{
    protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
    {
        if (request.Method == "POST")
        {
            var postData = request.PostData;
            if (postData != null)
            {
                var elements = postData.Elements;

                foreach (var element in elements)
                {
                    if (element.Type == PostDataElementType.Bytes)
                    {
                        var body = Encoding.UTF8.GetString(element.Bytes);
                        Debug.WriteLine("PostData#2:" + body);
                    }
                }
            }
        }

        return base.GetResourceRequestHandler(chromiumWebBrowser, browser, frame, request, isNavigation, isDownload, requestInitiator, ref disableDefaultHandling);
    }
}

In Debuging.
QQ截图20240418141536

In Code.
QQ截图20240418142943

Expected behavior

Correctly obtaining PostData.

Actual behavior

Unable to get PostData

Regression?

Yes, I encountered this issue in version 95 of CefSharp, and I can still reproduce it after upgrading to version 123.

Known Workarounds

No

Does this problem also occur in the CEF Sample Application

Yes using WPF/OffScreen command line args

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions