无法通过代码 post 数据但使用 swagger
Unable to post data through code but working with swagger
我正在向 post 数据调用以下行,它没有插入数据,但可以使用环回或 swagger
this.http.post(this.Root_url2 + 'busbookings', excelBody)
完整代码如下:
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
@Injectable()
export class LoadexcelService {
private Root_url2 = "http://localhost:3000/api/";
constructor( private http: HttpClient) {
}
postRouteList(routeExcel) {
routeExcel.forEach((route) => {
var excelBody = {
"routeid":route.routeid,
"from":route.from,
"to":route.to,
"price":route.price,
"departuredate":route.departuredate,
"departuretime":route.departuretime,
"arrivaldate":route.arrivaldate,
"busType":route.busType
}
this.http.post(this.Root_url2 + 'busbookings', excelBody)
});
}
}
我在 post 通过这个 link
大摇大摆地获取数据方面没有任何问题
Observable
在您订阅之前永远不会触发,因此您需要在每个 subscribe
上调用
this.http.post(this.Root_url2 + 'busbookings', excelBody)
.subscribe(res => console.log(res));
我正在向 post 数据调用以下行,它没有插入数据,但可以使用环回或 swagger
this.http.post(this.Root_url2 + 'busbookings', excelBody)
完整代码如下:
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
@Injectable()
export class LoadexcelService {
private Root_url2 = "http://localhost:3000/api/";
constructor( private http: HttpClient) {
}
postRouteList(routeExcel) {
routeExcel.forEach((route) => {
var excelBody = {
"routeid":route.routeid,
"from":route.from,
"to":route.to,
"price":route.price,
"departuredate":route.departuredate,
"departuretime":route.departuretime,
"arrivaldate":route.arrivaldate,
"busType":route.busType
}
this.http.post(this.Root_url2 + 'busbookings', excelBody)
});
}
}
我在 post 通过这个 link
大摇大摆地获取数据方面没有任何问题Observable
在您订阅之前永远不会触发,因此您需要在每个 subscribe
上调用
this.http.post(this.Root_url2 + 'busbookings', excelBody)
.subscribe(res => console.log(res));