其他分享
首页 > 其他分享> > Web Api 如何做上传文件的单元测试

Web Api 如何做上传文件的单元测试

作者:互联网

代码如下:

            //--------上传------------
            HttpClient client = new HttpClient();
            #region
            MultipartFormDataContent form = new MultipartFormDataContent();
            StreamContent fileContent = new StreamContent(File.OpenRead(@"D:\uni-all-resources\CloudShop\Source\Development\Uni2uni.iShop\Uni2uni.iShop.WebApi\UploadAudio\ios_2.pcm"));
            fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
            fileContent.Headers.ContentDisposition.FileName = "ios_2.pcm";
            form.Add(fileContent);
            #endregion

            HttpResponseMessage res = client.PostAsync("http://app.uni2uni.com/api/Audio/UploadAudioResponseMessage", form).Result;
            var uploadModel = res.Content.ReadAsStringAsync().Result;

 

转载于:https://www.cnblogs.com/Kummy/p/3688147.html

标签:Web,form,res,单元测试,Headers,Api,fileContent,new,ContentDisposition
来源: https://blog.csdn.net/weixin_34185364/article/details/93230607