I had this working before and now I do not. But, I cannot see what I have done to make it not work?
This is my MVC API Controller:
[HttpPost]
public Models.CustomerAddress Add(string Customer)
{
//the customer is a json string
}
This is my C# desktop Client:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Shared.URL);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Shared.HeaderType));
string jsonInput = JsonConvert.SerializeObject(customer);
HttpContent contentPost = new StringContent(jsonInput, Encoding.UTF8, "application/json");
var response = client.PostAsync(string.Format("http://myuri/api/Customer/Add?Customer="), contentPost).Result;
response.EnsureSuccessStatusCode();
string json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<Model.CustomerAddress>(json);
}
The customer object is definitely populated...
This does call my api but the Customer string is null??
customerobject just a string, or something more complex? Also, why are you passing an emptyCustomerquery string parameter? That may be confusing the model binder.Customerrather thanCustomerAddress