In my Windows phone app, I want to take a simple string url, and when that url is entered in a browser, it only shows a JSON string on the webpage, as a response.
So I want to enter that url in my app and just get that JSON string in return, How can I do it? I've tried following but getResponse function isn't present in Silverlight.
string strUrl = "http://.....";
WebRequest request = HttpWebRequest.Create(strUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = (Stream)response.GetResponseStream();
StreamReader readStream = new StreamReader(s);
string dataString = readStream.ReadToEnd();
response.Close();
s.Close();
readStream.Close();
I would use the HttpClient instead it is much easier to use. You need to add the HttpClient Nuget package to use it in the WP Silverlight project.
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
using (HttpClient client = new HttpClient())
{
string data = await client.GetStringAsync("http://msdn.microsoft.com");
}
}