Saturday, September 15, 2012

HttpWebRequest in Silverlight

HttpWebRequest in Silverlight

How to recreate the following code in Silverlight? I'm pretty lost when it comes to async.

public class StringGet  {      public static string GetPageAsString(Uri address)      {          string result = "";           // Create the web request          HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;           // Get response          using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)          {              // Get the response stream              StreamReader reader = new StreamReader(response.GetResponseStream());               // Read the whole contents and return as a string              result = reader.ReadToEnd();          }          return result;      }  

Answers & Comments...

Answer: 1
public void DownloadHtml(Uri address){   WebClient webClient = new WebClient();   webClient.DownloadStringCompleted += WebClientDownloadString_Complete;   webClient.DownloadStringAsync(address) }  private void WebClientDownloadString_Complete(object sender, DownloadStringCompletedEventArgs e) {   if (e.Error == null) {     string html = e.Result;   } } 
by : Mishahttp://stackoverflow.com/users/616737




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog