0

I'm working on an Android app, and I need to access the body of a Android.Webkit.IWebResourceRequestInvoker object to extract some data from a HTTP request.

However, when I try to access the Body property using reflection, it returns null.

Can anyone suggest a way to access the body of a IWebResourceRequest object in Android? Is there any other way to extract data from a HTTP request using this object?

public override WebResourceResponse ShouldInterceptRequest(Android.Webkit.WebView view, IWebResourceRequest request) {
            string url = request.Url.ToString(); // It's works
    
            // I want to get the body of the request
            // First attempt: (Doesn't work, both returns null)
var requestType = request.GetType();
var bodyProperty = requestType.GetProperty("Body", BindingFlags.NonPublic | BindingFlags.Instance);
            var bodyProperty2 = requestType.GetField("Body", BindingFlags.NonPublic | BindingFlags.Instance);

    // Second attempt: (Doesn't work)
    var body = (Stream)bodyProperty.GetValue(request);
            Debug.WriteLine("request body... " + body);
...
}
ephramd
  • 561
  • 2
  • 15
  • 41
  • You can check this [Call HTTP GET with JSON body content parameters](https://stackoverflow.com/questions/54319813/call-http-get-with-json-body-content-parameters). Someone provide the method by using the reflection to get the content body. – Guangyu Bai - MSFT Apr 27 '23 at 08:46

0 Answers0