小编Vie*_*yen的帖子

AggregateException "发生一个或多个错误。发送请求时发生错误。"

我试图将文件从我的 WCF .Net 框架 4.5 发布到 API 休息区。这是我的代码:

public string CreateConclusion(string[] instanceUIDs)
    {
        var root = @"C:\";
        string filename = "1.2.840.114257.1.9.1245.56421.52314.1119854.01248.dcm";

            using (var client = new HttpClient())
            {
                var stream = new FileStream(root + filename, FileMode.Open);

                using (var content =
                    new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
                {
                    content.Add(new StreamContent(stream), "fileToUpload", filename);

                    using (var message = client.PostAsync("https://localhost:44343/api/ConclusionReports/UploadFile", content).Result)
                    {
                        var input = message.Content.ReadAsStringAsync();

                        return !string.IsNullOrWhiteSpace(input.Result) ? Regex.Match(input.Result, @"http://\w*\.directupload\.net/images/\d*/\w*\.[a-z]{3}").Value : null;
                    }
                }
            }

    }
Run Code Online (Sandbox Code Playgroud)

它不起作用并抛出异常:“发生一个或多个错误。发送请求时发生错误。”

有没有人可以帮我解决这个问题?先感谢您

c# wcf httpclient

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

httpclient ×1

wcf ×1