HttpClient not supporting PostAsJsonAsync method C#

[Originally Posted By]:

I am trying to call a web api from my web application.Am using .net 4.5 and while writing the code i am getting an error HttpClient does not contain a definition PostAsJsonAsync method

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:51093/");
   new MediaTypeWithQualityHeaderValue("application/json"));
var user = new Users();
user.AgentCode = 100;
user.Remarks = "Test";
user.CollectionDate = System.DateTime.Today;
user.RemittanceDate = System.DateTime.Today;
user.TotalAmount = 1000;
user.OrgBranchID = 101;

var response = client.PostAsJsonAsync("api/AgentCollection", user).Result;

and I am getting the error message :

Error:  'System.Net.Http.HttpClient' does not contain a definition for 'PostAsJsonAsync' and
no extension method 'PostAsJsonAsync' accepting a first argument of type    
'System.Net.Http.HttpClient' could be found (are you missing a using directive or an 
assembly reference?)

Please have a look and advice me.


Yes, you need to add a reference to


This can be found in the extensions assemblies area.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s