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