Я хочу сделать вставку из удаленного клиента, потому что мне нужно отправить данные через http.
я могу использовать getPerformances()
правильно с httpClient
api/performances?date={0}
MVC 4 Web Api Post
Я хочу спросить, если мой postPorformances()
implemntation внутри моей PerformancesController
является corrrect, и если это то, как назвать это от клиента?
Вот моя реализация:
public class PerformancesController : ApiController
{
// GET api/performances
public IEnumerable<Performance> getPerformances(DateTime date)
{
return DataProvider.Instance.getPerformances(date);
}
public HttpResponseMessage postPerformances(Performance p)
{
DataProvider.Instance.insertPerformance(p);
var response = Request.CreateResponse<Performance>(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);
Если вызов ap/performances занимает много времени, возможно, вы захотите установить client.Timeout перед выполнением вызова – BlackTigerX