zoukankan      html  css  js  c++  java
  • HttpClient后台post 请求webapi

    1.请求方法
    /// <summary> /// httpClient 请求接口 /// </summary> /// <param name="url">地址</param> /// <param name="xmlString">提交数据 json格式</param> /// <returns></returns> private string PostResponse(string url, string xmlString) { HttpContent httpContent = new StringContent(xmlString); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpClient httpClient = new HttpClient(); HttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result; if (response.IsSuccessStatusCode) { Task<string> t = response.Content.ReadAsStringAsync(); return t.Result; } return string.Empty; }

      

     2.Api
          // POST api/values  
           public HttpResponseMessage Post([FromBody]string value)  
           {  
               return Request.CreateResponse(HttpStatusCode.OK, value);  
           }  
    

      

  • 相关阅读:
    第一次作业 黄学才
    shell重定向符
    umask
    Linux下新建用户自动复制文件
    任务计划cron
    vsftp配置
    xinetd.d配置格式
    php安装
    第五次作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/louby/p/7929402.html
Copyright © 2011-2022 走看看