Answer the question
In order to leave comments, you need to log in
What is wrong with POST request?
Good afternoon, in front-end development quite recently, so please treat with understanding
The problem is this:
I send a post request to the web api with the entered data and an error occurs with status 400.
The payload is empty, in response such an error The JSON value could not be converted to air_astana_webapi.Models.AirLine. Path: $ | LineNumber: 0 | BytePositionInLine: 1."
Here is the service code:
addAirline(data:any)
{
readonly airlineAPIUrl = 'https://localhost:44336/api'
debugger
return this.http.post(this.airlineAPIUrl + '/airlines', data);
}
AddAirline()
{
debugger
this.airLine.Id != 0;
this.airLine.companyName = this.company;
this.airLine.airLineStatus = this.status;
this.airLine.whereFrom = this.where;
this.airLine.whereFromTime = moment(this.timeWhere,"HH:mm").toISOString();
this.airLine.from = this.from;
this.airLine.fromTime = moment(this.timeFrom,"HH:mm").toISOString();
this.airLine.airLineDelayTime = this.delay;
this.service.addAirline(this.airLine).subscribe(res => {this.refreshAirlinesList()}, error=> {console.log(error)/*alert('Error')*/});
}
[HttpPost]
[Authorize]
public async Task<ActionResult<AirLine>> PostAirLines(AirLine airLine)
{
if (airLine == null)
{
return BadRequest();
}
else
_context.AirLines.Add(airLine);
await _context.SaveChangesAsync();
return CreatedAtAction("GetAirline", new { id = airLine.Id }, airLine);
}
public class AirLine
{
public int Id { get; set; }
public string CompanyName { get; set; }
[StringLength(30)]
public string AirLineStatus { get; set; } = string.Empty;
[StringLength(100)]
public string WhereFrom { get; set; } = string.Empty;
public DateTime WhereFromTime { get; set; }
[StringLength(100)]
public string From { get; set; } = string.Empty;
public DateTime FromTime { get; set; }
public int AirLineDelayTime { get; set; }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question