zoukankan      html  css  js  c++  java
  • .net core web api 与httpclient发送和接收文件及数据【转载】

    转:https://www.cnblogs.com/dayang12525/p/10688842.html

    客户端 HttpClient

    复制代码
             var url = $"https://localhost:44323/api/values/posttest?resource_source=yangwwmessage";
                    using (HttpClient _client = new HttpClient())
                    {
                        using (var multiContent = new MultipartFormDataContent())
                        {
                            var fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(imgPath));
                            multiContent.Add(fileContent, "file", Path.GetFileName(imgPath));
    
                            HttpResponseMessage response = _client.PostAsync(url, multiContent).Result;
                            string data = response.Content.ReadAsStringAsync().Result;
                        }
                    }
    复制代码

    服务端.net core Web Api 

    复制代码
            [HttpPost]
            [Route("PostTest")]
            public JsonResult PostTest()
            {
                var r = Request.Query["resource_source"].ToString();
                var files = HttpContext.Request.Form.Files;
                return new JsonResult("this is a test api for me") { StatusCode = 200 };
            }
    复制代码
  • 相关阅读:
    0427-2
    0427-1
    0426html常用标签属性
    HTML,标签学习
    oracle培训,HTML学习
    第三十七天
    第三十六天
    第三十五天
    第四十三天
    第四十二天
  • 原文地址:https://www.cnblogs.com/nnnnnn/p/14137739.html
Copyright © 2011-2022 走看看