LiveNVR二次开发接口jquery调用示例如何解决JS|axios调用接口时遇到的跨域问题
- 1、接口调用示例
- 2、JS调用遇到跨域解决示例
- 3、axios请求接口遇到跨域问题
- 3.1、post请求
- 3.2、get请求
- 4、RTSP/HLS/FLV/RTMP拉流Onvif流媒体服务
1、接口调用示例
下面是完整的 jquery 调用示例
$.ajax({url: "http://127.0.01:10800/api/v1/login",type: 'GET',data: {username:"test",password:"098f6bc4621d73cade4e8326274f6"},xhrFields: { withCredentials: true},crossDomain: true, success: function (ret) {console.log(ret)var token = ret.LiveQing.Body.Token;alert(token)getchannels(token)},error: function(xhr,textStatus,errorThrown){alert(xhr.status)}});<!--携带token调用其他接口示例 --> function getchannels(token) {$.ajax({url: "http://nvr.liveqing.com:10800/api/v1/getchannels",type: 'GET',data: {start:0,limit:10},xhrFields: { withCredentials: true},crossDomain: true, beforeSend: function (xhr) {xhr.setRequestHeader("cookie", "token="+token);},success: function (ret) {console.log(ret)alert(JSON.stringify(ret));},error: function(xhr,textStatus,errorThrown){alert(xhr.status)}});}
2、JS调用遇到跨域解决示例
添加 xhrFields: { withCredentials: true},crossDomain: true,
$.ajax({type: "GET",url: "http://other-domain:10800/api/v1/login",xhrFields: { withCredentials: true},crossDomain: true, data: {username: 'test',password: 'test'},success: function(data) {console.log(data);}
})
3、axios请求接口遇到跨域问题
添加 withCredentials: true
3.1、post请求
axios.post("http://ip:10800/api/v1/test", {param1: 'test',param2: 'test'}, {withCredentials: true}).then(res => {console.log(res)}).catch(err => {console.log(err);})
3.2、get请求
axios.get("http://ip:10800/api/v1/test", {params:{start:0,limit:10},withCredentials: true}).then(res => {console.log(res)}).catch(err => {console.log(err);})
4、RTSP/HLS/FLV/RTMP拉流Onvif流媒体服务
- 支持 Windows Linux 及其它CPU架构(国产、嵌入式…)操作系统
- 安装包下载 、 安装使用说明