第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在C#中的API響應(yīng)上在錯(cuò)誤goto下實(shí)現(xiàn)?

如何在C#中的API響應(yīng)上在錯(cuò)誤goto下實(shí)現(xiàn)?

C#
藍(lán)山帝景 2021-05-21 13:10:16
我有ID的列表,我正在遍歷這些ID中的每一個(gè)以獲取詳細(xì)信息。在少數(shù)情況下,API調(diào)用失敗。因此,我想跳過失敗的API調(diào)用,并希望繼續(xù)進(jìn)行下一個(gè)ID API調(diào)用;類似于on error goto next。foreach (var item in ID){    try    {        List<string> resultList = new List<string>();        url = string.Format(HttpContext.Current.Session["url"].ToString() +               ConfigurationManager.AppSettings["propertyURL"].ToString(),              HttpContext.Current.Session["ObjectID"].ToString(), item);        var request1 = WebRequest.Create(url);        request1.Headers["X-Authentication"] = HttpContext.Current.Session["vaultToken"].ToString();        request1.Method = "GET";        request.Headers.Add("Cache-Control", "no-cache");        //// Get the response.        var response1 = request1.GetResponse();        var deserializer1 = new DataContractJsonSerializer(typeof(PropertyValue[]));        var result1 = (PropertyValue[])deserializer1.ReadObject(response1.GetResponseStream());    }    catch (Exception ex)    {    }}有什么可能的解決方案,即使API調(diào)用失敗,foreach循環(huán)也將用于下一個(gè)ID API調(diào)用。
查看完整描述

2 回答

?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

實(shí)際上,這更加清楚。


Dictionary<int, string> resultList = new Dictionary<int, string>();


foreach (var item in ID)

{

   resultList.Add(item,string.Empty);

   try

   {

         // Your Call Here


         // Add Result to resultList here


       var apiCallResult = apiCall(item);

       resultList[item] = apiCallResult;

   }

   catch

   {

   }

}

您可以在字典中查詢ID沒有結(jié)果的。


查看完整回答
反對 回復(fù) 2021-05-23
  • 2 回答
  • 0 關(guān)注
  • 164 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號