Sarwar Hussain

Sarwar Hussain

  • NA
  • 423
  • 333.4k

HttpClient Post request arise an error?

Apr 21 2015 3:44 AM
 
 I am write a code as bellow for using windows phone :
 
private void Btn_Submit_Click(object sender, RoutedEventArgs e)
        {
            string urlPath = "http://192.168.1.84/manageit/servlet/uidServlet";
            using (HttpClient hc = new HttpClient(new HttpClientHandler()))
            {
                var values = new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("ticketId",tb_TicketNo.Text),
                    new KeyValuePair<string, string>("status","test"),
                    new KeyValuePair<string, string>("responseTime","test"),
                    new KeyValuePair<string, string>("clouserComment","test"),
                    new KeyValuePair<string, string>("date_time","test"),
                    new KeyValuePair<string, string>("lat","test"),
                    new KeyValuePair<string, string>("longitude","test"),
                    new KeyValuePair<string, string>("barcode","test"),
                    new KeyValuePair<string, string>("CustName","test"),
                    new KeyValuePair<string, string>("CustDesignation","test"),
                    new KeyValuePair<string, string>("user_id","test"),
                    new KeyValuePair<string, string>("remark","test"),
                    new KeyValuePair<string, string>("observation_date","test")
                };

                var content = new FormUrlEncodedContent(values);
                var response = await hc.PostAsync(urlPath, content);
            }
        }
But  await hc.PostAsync(urlPath, content);  Aries an error is
 
"The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'."
 

Answers (2)