https://www.codebye.com/c-sharp-webclient-vs-httpclient.html  两者之间的差别

https://www.cnblogs.com/PatrickLiu/p/9264648.html  HttpClient请求方式预热和长连接的问题,通过预热和长连接方式减少请求时间

 

使用 HttpClientFactory 方式请求第三方API

https://www.jianshu.com/p/732aee097c6b?from=timeline

 

HttpClient和WebClient的区别

1.HttpClient方式

 HttpClient webClient = new HttpClient(); 
 webClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);  
                var formdata = new MultipartFormDataContent
                {
                    { new StringContent(originalFileName), "fileRelativePath" },
                    { new StringContent(fileName),"fileGuidPath"},
                    { new StringContent(userid.ToString()),"userid" }
                };  
                await webClient.PostAsync($"{_configuration.GetSection("OAServerAddress").Value}/api/services/AppApi/Customers/EditHead", formdata);

2.WebClient方式

  var requst_sour = new Dictionary<string, object>
            {
                { "usernameOrEmailAddress", "admin" },
                { "Password", "123qwe" } 
            };
            var requst_sourStr = Encoding.UTF8.GetBytes(requst_sour.ToJsonString());

            var webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/json");
            var reponseByte= webClient.UploadData($"{_configuration.GetSection("OAServerAddress").Value}/api/TokenAuth/Authenticate ", "POST", requst_sourStr);
            var bearerToken = Encoding.UTF8.GetString(reponseByte);
            var token = JsonConvert.DeserializeObject<dynamic>(bearerToken);
            return token.result.accessToken; 

 

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2021-05-16
  • 2021-11-11
  • 2021-03-08
  • 2021-10-20
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2019-10-22
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案