我想问一下如何在这个httpclient代码中添加一个foreach循环。我是新手。
var client = new HttpClient();
var url = new Uri(URL+ "/GetAll");
var content = new StringContent("{Code: '(this should be taken from a table column)'}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
var objResult = JsonConvert.DeserializeObject<SrpResult>(result);
var jsonlist = JsonConvert.SerializeObject(objResult, Formatting.Indented);
var str = "EXEC dbo.JSON @json";
Sql.ExecNonQuery(str, jsonlist);
答案 0 :(得分:0)
你的意思是这样吗
using(var client = new HttpClient())
{
var url = new Uri(IAMSUrl + "/GetSRP");
var content = new StringContent("{CustomerCode: '(this should be taken from a table column)'}");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
var objResult = JsonConvert.DeserializeObject<SrpResult>(result);
var jsonlist = JsonConvert.SerializeObject(objResult, Formatting.Indented);
var str = "EXEC dbo.JSONToTEPP_SRP @json";
foreach(var json in jsonlist)
{
Sql.ExecNonQuery(str, json);
}
}