亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AggregateException "發生一個或多個錯誤。發送請求時發生錯誤。"

AggregateException "發生一個或多個錯誤。發送請求時發生錯誤。"

C#
喵喵時光機 2021-10-31 10:13:41
我試圖將文件從我的 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;                    }                }            }    }它不起作用并拋出異常:“發生一個或多個錯誤。發送請求時發生錯誤?!庇袥]有人可以幫我解決這個問題?先感謝您
查看完整描述

1 回答

?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

總是可以解開聚合異常以發現真正的原因。嘗試在 try-catch 中編寫您的客戶端調用,如下所示:


    try {



    //Some risky client call that will call parallell code / async /TPL or in some way cause an AggregateException 


   }

   catch (AggregateException err){

    foreach (var errInner in err.InnerExceptions) {

     Debug.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary 

     }   

   }


查看完整回答
反對 回復 2021-10-31
  • 1 回答
  • 0 關注
  • 314 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號