Issue
When I tried this code in a normal Console app project it works, but it doesnt work on xamarin, the exception occurs in
" using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) "
string html = string.Empty;
string url = $"https://stackoverflow.com/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
Solution
I'd suggest trying HttpClient instead
var client = new HttpClient();
var response = await client.GetAsync("http://www.contoso.com/");
string responseBody = await response.Content.ReadAsStringAsync();
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.