使用httpclient实现http请求是非常常见的方式,有一个httpclient的拓展类httpclientextensions提供了更多的拓展方法,包括但不限于

  • postasjsonasync
  • postasxmlasync
  • putasjsonasync
  • putasxmlasync

.net 4.5之前httpclientextensions在system.net.http.dll,从.net 4.5开始httpclientextensions在system.net.http.formatting.dll
查证来源:httpclientextensions methods (system.net.http) | microsoft docs

根据 json – httpclient not supporting postasjsonasync method c# – stack overflow 和 cs1061 ‘httpclient’ does not contain a definition for ‘postasjsonasync’ for asp.net core project · issue #3849 · aspnet/aspnetcore.docs可以得出以下3种解决办法。

  1. 根据postasync或者sendasync实现
  2. 引用微软官方出的nuget包microsoft.aspnet.webapi.client,nuget gallery | microsoft.aspnet.webapi.client 5.2.7
  3. 引用他人出的nuget包
    • nuget gallery | webapirestservice.webapiclient 1.1.0
    • nuget gallery | system.net.http.formatting.extension 5.2.3
    • nuget gallery | wininsider.system.net.http.formatting 1.0.5

microsoft.aspnet.webapi.client依赖

.netframework 4.5
newtonsoft.json (>= 6.0.4)
.netstandard 2.0
newtonsoft.json (>= 10.0.1)
newtonsoft.json.bson (>= 1.0.1)
portable class library (.netframework 4.5, .netcore 4.5, windowsphone 8.0, windowsphone 8.1, windowsphoneapp 8.1)
microsoft.net.http (>= 2.2.22)
newtonsoft.json (>= 6.0.4)