异步请求Url

2021-02-20 19:20

阅读:498

标签:url   sys   message   请求   异步请求   异步   ons   res   cat   

 public static System.Xml.Linq.XElement Post(HttpClient _myhttp,   string url, XmlDocument doc)
        {          
            HttpContent content = new StringContent(doc.InnerXml, Encoding.UTF8, "application/xml");
            var message = Task.Run(() =>
            {
                return _myhttp.PostAsync(url, content);
            });
            message.Wait();
            //接收返回得信息
            if (message.Result.IsSuccessStatusCode)
            {
                var s = Taskstring>.Runstring>(() =>
                {
                    return message.Result.Content.ReadAsStringAsync();
                });
                s.Wait();
                return System.Xml.Linq.XElement.Load(s.Result);
            }
            else
            {
                throw new Exception("StatusCode:" + message.Result.StatusCode.ToString());
            }
        }

 

异步请求Url

标签:url   sys   message   请求   异步请求   异步   ons   res   cat   

原文地址:https://www.cnblogs.com/ZkbFighting/p/12915196.html


评论


亲,登录后才可以留言!