我正在尝试向我的.NET CORE WEB API发出POST请求。有时它有效,有时不起作用。我真的很困惑。
const headers = Object.assign({'Content-Type': 'application/json'}, this.requestHeaders());
this.requestHeaders()包含我的jwt令牌
const request = new Request(`http://localhost:50873/api/add`, {
method: 'POST',
headers: headers,
body: JSON.stringify(inputInfo)
});
return fetch(request).then(response => {
return response.json()
}).catch(error => {
return error;
});
这是我的inputInfo字符串化:
{"AppointmentId":215,"Date":"12/03/2016","Time":"12:30","AppointmentStatus":"Confirmed","Description":"description","PatientId":"3","DentistId":"2"}
在后端到达null。
后端:
[Route("add")]
[HttpPost]
public IActionResult AddAppointment([FromBody] AddInputInfo inputInfo) {
我的AddInputInfo类:
public class AddInputInfo{
public int AppointmentId { get; set; }
public DateTime Date { get; set; }
public DateTime Time { get; set; }
public string AppointmentStatus { get; set; }
public string Description { get; set; }
public int PatientId { get; set; }
public int DentistId { get; set; }
public AddInputInfo() { }
}
有时一切都很完美,有时我的inputInfo在后端到达null但不应该。