Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Displaying form posting in new WebView.

$
0
0

I'm back. Sorry guys. :(

I'm working on serializing an object to Json and then using that as post data. That post data is sent via HttpWebRequest and the HttpWebResponse returns HTML. I want that HTML to be the source code for a WebView, but all I'm getting is a blank page.

The page has a grid, and I clear all the children from the grid and re-initialize the RowDefinitions and ColumnDefinitions as new collections with one each. Height and Width both equal GridLength.Star. Here's what comes next, along with some comments as to what works and what doesn't. It's really just the two last lines that aren't seeming to do anything. Any suggestions are super welcome.

PageGrid.Children.Clear();
PageGrid.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star } };
PageGrid.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Star } };
WebView myWebView = new WebView { VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.StartAndExpand };
PageGrid.Children.Add(myWebView);

var webRequest = WebRequest.Create("https:// some website") as HttpWebRequest;
webRequest.Method = "POST";
FormData formData = new FormData { initialized the object here };

var postData = await Task.Run(() => JsonConvert.SerializeObject(formData));
var postBytes = Encoding.UTF8.GetBytes(postData);
using (var dataStream = await webRequest.GetRequestStreamAsync())
dataStream.Write(postBytes, 0, postBytes.Length);

HttpWebResponse webresponse = await webRequest.GetResponseAsync() as HttpWebResponse;
var responseData = webresponse.GetResponseStream();
var responseReader = new StreamReader(responseData);
var responseString = responseReader.ReadToEnd();

//UP THROUGH HERE IT WORKS! When I step through it, responseString has the HTML source I want to use.

myWebView = new WebView { Source = responseString };

//And here's what doesn't work. I've tried moving where I declare myWebView to this line, but that didn't help either.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>