Ejemplo n.º 1
0
 /// <summary>
 /// 设置http头
 /// </summary>
 /// <param name="headerKey"></param>
 /// <param name="headerValue"></param>
 /// <returns></returns>
 public IEasyHttpClient SetHeader(string headerKey, string headerValue)
 {
     if (!HeaderDic.Any((h) => h.Key.ToLower() == headerKey.ToLower()))
     {
         HeaderDic.Add(headerKey, headerValue);
     }
     return(this);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// delete动作提交
 /// </summary>
 /// <param name="uriStr"></param>
 /// <returns></returns>
 public Task <string> Delete(string uriStr, string data = "")
 {
     using (HttpClient client = new HttpClient())
     {
         var uri = new Uri(uriStr);
         client.BaseAddress = uri;
         if (HeaderDic.HasItem())
         {
             foreach (var item in HeaderDic)
             {
                 client.DefaultRequestHeaders.Add(item.Key, item.Value);
             }
         }
         using (var msg = client.DeleteAsync(uri).ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode()))
         {
             var r = msg.Result.Content.ReadAsStringAsync();
             return(r);
         }
     }
 }