我想从远程客户端插入,因为我需要通过http发送数据.
我可以getPerformances()正确使用httpClient api/performances?date={0}
我想问一下我的postPorformances()内部实现PerformancesController是否正确以及是否如何从客户端调用它?
这是我的实现:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
public class Performance {
public int Id {get;set;}
public DateTime Date {get;set;}
public decimal Value {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我试过这个,但我要注意:
private readonly HttpClient _client;
string request = String.Format("api/performances");
var jsonString = "{\"Date\":" + p.Date + ",\"Value\":" + p.Value …Run Code Online (Sandbox Code Playgroud) 是response.redirect始终是http GET响应吗?否则可能是POST?