首页 > 解决方案 > 检索发布请求响应并存储到角度 8 中的变量中

问题描述

我正在使用 lambda 的人脸识别和人脸检测api,并且应该使用 post 从 api 获得响应。通常我使用 get 来获取回复,而我使用 post 来发送回复。如何使用 post 获得此响应,以便判断图像是否已被识别?我的代码如下:

Node.js 文件

facedetAPIRoutes.route("/").post(function (req, res){
    let imageUrl = req.body.url;
    myFaceDetAPI.recognizeImg(imageUrl);
});

服务文件

sendImage(imgUrl){
    console.log(imgUrl);
    const obj = {
      url: imgUrl
    };    

    this.http.post(`${this.uri}`, obj)
      .subscribe(res => {
        console.log("this is res: " + res);
        console.log('image sent to api done');
      });
  }

组件文件

public handleImage(webcamImage: WebcamImage): void {
    console.info("received webcam image", webcamImage);
    this.webcamImage = webcamImage;
    console.log("this is: " + this.webcamImage.imageAsDataUrl);
    //this.fda.sendImage(this.webcamImage.imageAsDataUrl);
    this.fda.sendImage("http://localhost:4000/uploads/1570563000257-arnold4.jpg");
  }

标签: javascriptangulartypescripthttp

解决方案


你好。您可以使用响应的状态码。200 状态码为操作成功状态。或者如果错误,它会向您发送状态码 4xx。您可以阅读有关状态代码的更多信息https://en.wikipedia.org/wiki/List_of_HTTP_status_codes


推荐阅读