In a win App I want to get a Json from a url with a username and password and show the Json in a richTextBox.I use the below code but the "myMethod()" method is waiting all the time?! what's wrong in my code? I use .net 4.5 thank you ...
async static Task<dynamic> myMethod()
{
NetworkCredential credentials = new NetworkCredential("username", "password");
var handler = new HttpClientHandler { Credentials = credentials, AllowAutoRedirect = true };
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent" ,"Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12");
var responseString = await client.GetStringAsync("http://myURL.php");
dynamic stuff = Newtonsoft.Json.JsonConvert.DeserializeObject(responseString
return stuff ; }
private void button2_Click(object sender, EventArgs e)
{
dynamic d=myMethod().Result;
richTextBox1.Text = d.ToString();
}