MVC 4 Web Api Post
Я хочу сделать вставку с удаленного клиента для этого мне нужно отправить данные через http.
Я могу использоватьgetPerformances()
правильно сhttpClient
api/performances?date={0}
Я хочу спросить, если мойpostPorformances()
реализация внутри моегоPerformancesController
правильно и если это как позвонить с клиента?
Вот моя реализация:
public class PerformancesController : ApiController
{
// GET api/performances
public IEnumerable getPerformances(DateTime date)
{
return DataProvider.Instance.getPerformances(date);
}
public HttpResponseMessage postPerformances(Performance p)
{
DataProvider.Instance.insertPerformance(p);
var response = Request.CreateResponse(HttpStatusCode.Created, p);
return response;
}
}
public class Performance {
public int Id {get;set;}
public DateTime Date {get;set;}
public decimal Value {get;set;}
}
Я пробовал это, но яЯ уверен, что:
private readonly HttpClient _client;
string request = String.Format("api/performances");
var jsonString = "{\"Date\":" + p.Date + ",\"Value\":" + p.Value + "}";
var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
var message = await _client.PutAsync(request, httpContent);