cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.84k stars 2.92k forks source link

Unable to get PostData from IRequest #4783

Closed aiqinxuancai closed 5 months ago

aiqinxuancai commented 5 months ago

Is there an existing issue for this?

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