nodejs发起HTTPS,GET,POST请求Face++人脸识别
2017-10-12 18:36
483 查看
最近在鼓捣人脸识别,最开始使用了百度AI大脑的人脸识别,有nodejs的SDK包,使用起来也比较方便。但是每日有限额。找了找看到旷视(Face++)试用版本是没有限额的,虽然不保证并发,应该也够用了。
Face++接口使用https协议可以参考Nodejs官方文档:
https://nodejs.org/api/https.html#https_class_https_agentconst https = require('https'); const querystring = require('querystring'); var data = querystring.stringify({ api_key:"", api_secret:"", image_url:""//图片地址,接口支持base64,图片地址和imagefile }) const options = { host:'api-cn.faceplusplus.com', path:'/facepp/v3/detect', method:'POST', headers:{ 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8' } } const req = https.request(options, (res) => { console.log('statusCode:', res.statusCode); console.log('headers:', res.headers); res.on('data', (d) => { console.log(''+d);//将buffer转为字符串或者使用d.toString() let b = JSON.parse(''+d);//将buffer转成JSON console.log(b.image_id); }); }); req.on('error', (e) => { console.error(e); }); req.write(data); req.end();
返回结果为:
{ "image_id": "SSoY2Bnir0iDPGdnKR6XzA==", "request_id": "1507806917,f98fb976-73c1-4788-817d-2ba2532b612f", "time_used": 330, "faces": [{ "face_rectangle": { "width": 217, "top": 232, "left": 379, "height": 217 }, "face_token": "c5bead2221a6a7d9b7e5134d15d03c5a" }] }
faces数组为图片中检测到的人脸
nodejs发起POST请求步骤
引用https定义所要传输参数,比如data对象
定义发起请求的参数,host,path,method等,默认443端口
https.request创建请求,请求内监听response
监听请求错误
写入请求数据,比如data对象
结束请求
相关文章推荐
- 使用nodejs发起get或post请求抓取网页内容,支持中文编码
- nodejs 发起http get post 请求
- nodejs之get/post请求的几种方式
- php如何发起POST DELETE GET POST 请求
- .NET/C#发起GET和POST请求的几种方法
- android 网络协议等socket,http,HTTPS,get。post请求 等详解
- nodejs的request创建的get和post请求,带参数
- 为什么axios请求接口会发起两次请求(OPTIONS 和POST或者GET)
- golang使用http client发起get和post请求示例
- 【HttpClient】JAVA利用HttpClient进行POST和GET请求(HTTPS)
- PHP:CURL分别以GET、POST方式请求HTTPS协议接口api
- golang使用http client发起get和post请求示例
- Python向PHP发起GET与POST请求
- nodejs之koa2请求示例(GET,POST)
- golang使用http client发起get和post请求示例
- OkHttp3封装,可链式调用,目前包括post,get,上传、下载文件,及https请求加证书
- angularJS 发起$http.post和$http.get请求的实现方法
- php如何发起POST DELETE GET POST 请求
- java http get post请求 https请求实现
- JAVA利用HttpClient进行POST和GET请求(HTTPS)