HttpClient not supporting PostAsJsonAsync method C#

前端 未结 12 966
花落未央
花落未央 2020-11-27 10:37

I am trying to call a web API from my web application. I am using .Net 4.5 and while writing the code I am getting the error HttpClient does not contain a defin

相关标签:
12条回答
  • 2020-11-27 11:06

    Instead of writing this amount of code to make a simple call, you could use one of the wrappers available over the internet.

    I've written one called WebApiClient, available at NuGet... check it out!

    https://www.nuget.org/packages/WebApiRestService.WebApiClient/

    0 讨论(0)
  • 2020-11-27 11:16

    If you're playing around in Blazor and get the error, you need to add the package Microsoft.AspNetCore.Blazor.HttpClient.

    0 讨论(0)
  • 2020-11-27 11:17

    I know this reply is too late, I had the same issue and i was adding the System.Net.Http.Formatting.Extension Nuget, after checking here and there I found that the Nuget is added but the System.Net.Http.Formatting.dll was not added to the references, I just reinstalled the Nuget

    0 讨论(0)
  • 2020-11-27 11:21

    The missing reference is the System.Net.Http.Formatting.dll. But the better solution is to add the NuGet package Microsoft.AspNet.WebApi.Client to ensure the version of the formatting dll worked with the .NET framework version of System.Net.Http in my project.

    0 讨论(0)
  • 2020-11-27 11:21

    Ok, it is apocalyptical 2020 now, and you can find these methods in NuGet package System.Net.Http.Json. But beware that it uses System.Text.Json internally.

    And if you really need to find out which API resides where, just use https://apisof.net/

    0 讨论(0)
  • 2020-11-27 11:24

    Try to install in your project the NuGet Package: Microsoft.AspNet.WebApi.Client:

    Install-Package Microsoft.AspNet.WebApi.Client
    
    0 讨论(0)
提交回复
热议问题