如果我的问题很重复,我很抱歉,但是我已经尝试解决了2天。
我在localhost:4000
处有一个成角度的表格,我想将其数据发布到localhost:4000/api/scheduled
上的api中,但是每一个都会出现500错误。
然后,这些数据可能会从api发送到mariadb。 我可以意识到从mariadb到angular的请求,但是发布不起作用。
我精确了,但我认为将表格从angular张贴到api的错误。
我尝试了很多事情,例如调整标头,通过减小标头发送的数据……但没有任何效果。
onSubmitScheduled() {
let OndemandScheduledRequest = this.formatRequestScheduled(this.selectedHotel, this.selectedCheckInDate, this.selectedCheckOutDate, this.selectedNumber, this.selectedCurrency, this.selectedReportName, this.selectedUser, this.selectedEmail, this.selectedFormat);
console.log(OndemandScheduledRequest);
this.saveScheduledRequest(OndemandScheduledRequest);
this.openDialog();
}
saveScheduledRequest(onDemandScheduledRequest: OnDemandScheduledRequest) {
console.log(onDemandScheduledRequest);
/* var headers = new HttpHeaders();
headers.append('Content-Type', 'application/form-data');
*/
return this.http.post('http://localhost:4000/api/scheduled',onDemandScheduledRequest )
.subscribe(
response => {
debugger;
console.log(response)
},
(err : HttpErrorResponse)=> console.log({
err
},))
}
这里是发布接口(我已经导入)中定义的对象的函数:
export interface OnDemandScheduledRequest {
id: string,
user: string,
email: string,
reportName: string,
format: string,
submissionDate: string,
Name: string,
checkIn: string,
checkOut: string,
guests: string,
currency: string,
status: boolean,
}
以下是使用以下表单字段创建此接口实例的函数:
formatRequestScheduled(selectedHotel, selectedCheckInDate, selectedCheckOutDate, selectedNumber, selectedCurrency, selectedReportName, selectedUser, selectedEmail, selectedFormat ) :
//AS MANY RESULTS AS REQUESTED HORIZONS.
any{
let DemandScheduledRequest = {
id: '1',
user: selectedUser.toString(),
email: selectedEmail.toString(),
reportName: selectedReportName.toString(),
format: selectedFormat.toString(),
submissionDate: new Date(),
Name: selectedHotel.toString(),
checkIn: selectedCheckInDate,
checkOut: selectedCheckOutDate,
guests: selectedNumber.toString(),
currency: selectedCurrency.toString(),
status: false,
}
return DemandScheduledRequest;
}
感谢您的帮助。