It appears ObjectContent
didn't make it among the various subclasses of HttpContent
(StreamContent
, StringContent
, etc.). Is this a bug or is there another way to use HttpClient
to POST json somewhere?
e.g.
var value = new MyType();
client.PostAsync("http://example.com/", new ObjectContent<MyType>(value, new JsonMediaTypeFormatter()))
The set of *Content classes in HttpClient is the same as .NET Framework.
ASP.NET WebAPI did have a set of extension classes with JSON formatting.
cc: @danroth27
Ah, thanks I see now. After reading aspnet/Mvc#1639, I added a reference to Microsoft.Aspnet.WebApi.Client package and it now works even though that package doesn't explicitly target .net core.
Will that package be updated to target .net core?
Will that package be updated to target .net core?
The ASP.NET team can answer that question better. Feel free to open an issue on the aspnet/mvc repo.
Can you tell me , what should I replace the
C#
Content = new ObjectContent<ClubUserDto>(user, new JsonMediaTypeFormatter(), "application/json")
in .net core now?
The ASP.NET team owns the libraries that contain the ObjectContent
class. It is not part of the .NET Framework and is not part of .NET Core itself.
Please follow up with @danroth27. I also suggest you ask this question in the ASP.NET repo:
https://github.com/aspnet/home
@Eilon @dougbu I believe the work is pretty much done. We are just waiting to align the release with the next update of ASP.NET Web API 2. You can grab the latest build of the package from http://myget.org/gallery/aspnetwebstacknightly.
Yup I think we're very close to getting this out. We have most of the legwork done, and in the meantime you can try out the nightly package feed to see that it resolves the issues you have with .NET Core support.
Try to use JsonSerializer + StringContent
For anyone interested, you can add a reference to the .net standard compatible Microsoft.AspNet.WebApi.Client v5.2.4 which is not released yet because reasons.
See aspnet/Mvc#5822
We plan to release Microsoft.AspNet.WebApi.Client 5.2.4 in the next month or so pending final verification.
Most helpful comment
Can you tell me , what should I replace the
C# Content = new ObjectContent<ClubUserDto>(user, new JsonMediaTypeFormatter(), "application/json")
in .net core now?