首页 > Web开发 > 详细

HttpClient 上传文件带参数 ContentType 记录

时间:2020-07-02 20:47:20      阅读:152      评论:0      收藏:0      [点我收藏+]
参考博文地址 
https://www.cnblogs.com/cplemom/p/11264040.html
https://www.cnblogs.com/netcs/p/12789162.html
  var client = _httpClientFactory.CreateClient();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue($"multipart/form-data"));
                var content = new MultipartFormDataContent();
                content.Add(new StringContent(type), "type");
                byte[] arr;
                using (Stream fileStream = file.OpenReadStream())
                {
                    arr = new byte[fileStream.Length];
                    fileStream.Read(arr, 0, arr.Length);
                }
                var upFileContent = new ByteArrayContent(arr);
                upFileContent.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType);
                content.Add(upFileContent, "file", file.FileName);
                var reponse = await client.PostAsync("ip地址/api/FileUpload/ImageUpload", content);

  主要还是橙色代码块 设置文件ContentType

不设置这个 接口端File.ContentType是接收不到类型的

HttpClient 上传文件带参数 ContentType 记录

原文:https://www.cnblogs.com/litianfeng-net/p/13226816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!