javascript - 检索发布请求响应并存储到角度 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");
}
解决方案
你好。您可以使用响应的状态码。200 状态码为操作成功状态。或者如果错误,它会向您发送状态码 4xx。您可以阅读有关状态代码的更多信息https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
推荐阅读
- html - NUXTJS | 第一次调用加载 css / layout 时出错
- kotlin - 在不传播的情况下访问对象中的 ApplicationCall
- c# - 每帧更新bufferarray OpenTK
- spring-boot - 获取用户位置并在 Spring Boot Web 应用程序上显示的最佳方法是什么
- angular - Angular/rxJs concatMap - 进行两个 web api (http) 调用,要么不完成,要么控制移动到后续行
- sql - 如何从 SQL Server 中具有列 time_stamp 条件的表中选择插入?
- recursion - 使用递归从二叉搜索树中删除节点
- html - 为什么我不能在文本周围环绕图像?
- java - 如何检查图像视图是否有从 Android Studio 中的图库上传的图像?
- ssh - 将密码保护的私有 SSH 密钥传输到另一台机器