2
votes

Is it possible to get the content of a WebView as a string?

I tried using:

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Constants.LOGIN_URL);

HttpWebResponse response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();

But I didn't get what i wanted because the webview stores the sessions etc.

I want a method to get the data of a logged in user from a website if this is possible.

1

1 Answers

2
votes

Since you need to download the content of the WebView in the context of a logged in user, you may want to try injecting JavaScript into the WebView and then having the JavaScript send code back to a C# method.

An example of something like this can be found in XLabs' Hybrid WebView (which is the example I used to call JavaScript from C# methods).

Have a look at the URL below. You will need to create a custom renderer for each platform that you support but that should just be a matter of copying and pasting from the link below.

Once you have you custom renderer all set, you can simply pull all of the HTML using a JavaScript method.

https://github.com/XLabs/Xamarin-Forms-Labs/wiki/HybridWebView

Reply back if you run into any road blocks.