Runtime: Missing ObjectContent class in System.Net.Http

Created on 27 Feb 2016  路  10Comments  路  Source: dotnet/runtime

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()))
area-System.Net

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?

All 10 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitAntoinee picture GitAntoinee  路  3Comments

bencz picture bencz  路  3Comments

jkotas picture jkotas  路  3Comments

sahithreddyk picture sahithreddyk  路  3Comments

Timovzl picture Timovzl  路  3Comments