这边打算学习一下人脸识别技术,调用了百度云的人脸识别接口,但是在html中获取token的get请求和人脸的post接口是报跨域的
var baiduAccessTokenApi ='https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' +your_client_id + '&client_secret=' + your_client_secret;
$.ajax({
url: baiduAccessTokenApi,
method: 'GET',
dataType: 'json',
success(res) {
console.log(res)
}
})
报跨域
前端这边没有好的方法能够处理吗
自己回答一下,这边处理好了。但是不是最好的方法。我是把这个html页面用uniapp的web-view嵌套就去,然后再根据manifest.json来配置跨域。接口可以调用,数据也返回来,证明接口没有写错
本地安装nginx,进行nginx代理
浏览器装个跨域插件就好了