I have a hangfire job build in C# .netcore. This job is making postasync call inside a forloop. After first call to api, it is throwing below error.
This instance has already started one or more requests. Properties can only be modified before sending the first request
How to make post call synchronously in a loop effectively? Call needs to be synchronous.
class myclass
{
public void process(){
_httpClient = new HttpClient();
foreach(var item in list){
_httpClient.BaseAddress = baseUri;
_httpClient.DefaultRequestHeaders.Clear();
_httpClient.DefaultRequestHeaders.ConnectionClose = true
var res= _httpClient.PostAsync(url,body);
var result= res.content.readasstringasync().Result;
saveResultInDB(result);
}
}