Httpclient This instance has already started one or more requests. Properties can only be modified before sending the first request

后端 未结 3 560
梦如初夏
梦如初夏 2021-02-03 22:29

I am creating an application in .Net Core 2.1 and I am using http client for web requests. The issue is I have to send parallel calls to save time and for that I am using Task.W

3条回答
  •  盖世英雄少女心
    2021-02-03 23:06

    Maybe my two cents will help someone.

    I ran into this issue when refreshing the page when debugging the application.

    I was using a singleton, but each refresh, it was trying to set the base address. So I just wrapped it in a check to see if the base address had already been set.

    The issue for me was, it was trying to set the baseAddress, even though it was already set. You can't do this with a httpClient.

    if (_httpClient.BaseAddress == null)
    {
        _httpClient.BaseAddress = new Uri(baseAddress);
    }
    

提交回复
热议问题