代码之家  ›  专栏  ›  技术社区  ›  SmartestVEGA

无法通过代码发布数据,但使用Swagger

  •  -1
  • SmartestVEGA  · 技术社区  · 6 年前

    我调用下面的行来发布数据,这些数据不是插入数据,而是与回送或招摇过市一起工作。

    < Buff行情>

    this.http.post(this.root_rl2+“BusBookings”,ExcelBody)

    < /块引用>

    完成以下代码:

    import httpclient from“@angular/common/http”;
    从“@angular/core”导入可注射;
    “注入”()
    导出类LoadExcelService{
    private root_url2=“http://localhost:3000/api/”;
    构造函数(私有http:httpclient){
    }
    
    PostRouteList(路由器Excel){
    routeexcel.foreach((route)=>。{
    
    变量ExcelBody={
    “routeid”:route.routeid,
    “从”:路由。从,
    “to”:Routh. to,
    “价格”:route.price,
    “出发日期”:Route.DepartureDate,
    “离港时间”:Route.DepartureTime,
    “到达日期”:route.arrivaldate,
    “总线类型”:route.busttype
    }
    this.http.post(this.root_rl2+“BusBookings”,ExcelBody)
    (});
    }
    }
    < /代码> 
    
    

    我在通过这个链接大摇大摆地发布数据时没有任何问题

    http://localhost:3000/api/

    .

    完整代码如下:

        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)    
           }); 
             }
        }
    

    我在通过这个链接大摇大摆地发布数据时没有任何问题

    http://localhost:3000/api/

    1 回复  |  直到 6 年前
        1
  •  1
  •   user184994    6 年前

    Observable S在你订阅之前不会被解雇,所以你需要打电话 subscribe 在每一个

    this.http.post(this.Root_url2 + 'busbookings', excelBody)
             .subscribe(res => console.log(res));