Reputation: 11878
I'm wondering if I can get POST data of the WebView
request in UWP.
I'm using WebView_NavigationStarting
event to get information about URI, but I have custom page which sent some information back to the app inside the POST request. Ideally I want to do this:
private void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
Stream receiveStream = args.Request.InputStream;
}
But args
doesn't have Request
, only Uri
. I was able to do this trick in iOS and Android (iOS, for example, pass the whole request to the similar event so why it's possible). Is there way to do so in UWP C# app ?
Upvotes: 2
Views: 942
Reputation: 314
You can try listen to WebResourceRequested, the args contains both request and response object. It should be in args.request.Content. But so far I cannot access those content too.
private void WebView_WebResourceRequested(WebView sender, WebViewWebResourceRequestedEventArgs args)
{
if (args.request.Method.Method == "POST")
{
HttpStreamContent content = (HttpStreamContent) args.request.Content;
var contentBuffer = content.ReadAsBufferAsync().GetResults();
byte[] buffer = contentBuffer.ToArray();
}
}
Upvotes: 1