How to initialize WebClient using object initializers?

后端 未结 2 563
别跟我提以往
别跟我提以往 2021-01-19 13:27

I have a WebClient like this:

WebClient _webClient = new WebClient
{
    UseDefaultCredentials = true,
    Encoding = System.Text.Encoding.UTF8,         


        
2条回答
  •  梦谈多话
    2021-01-19 14:14

    I think you can also do it like this (without the : in the header):

    private static WebClient _doClient = new WebClient
    {
        BaseAddress = "https://api.digitalocean.com/v2/domains/example.com/",
        Headers = new WebHeaderCollection { { "Authorization", "Bearer " + _digitalOceanApiKey } }
    };
    

提交回复
热议问题