0
点赞
收藏
分享

微信扫一扫

如何解决JS|axios调用LiveGBS(GB28181国标流媒体服务)接口时遇到的跨域问题


GB28181流媒体服务搭建

搭建入口,解压启动即用:​​https://www.liveqing.com/docs/download/LiveGBS.html​​

JS调用遇到跨域解决示例

添加 xhrFields: { withCredentials: true},crossDomain: true,

$.ajax({
type: "GET",
url: "http://other-domain:10000/api/v1/login",
xhrFields: {
withCredentials: true
},
crossDomain: true,
data: {
username: 'test',
password: 'test'
},
success: function(data) {
console.log(data);
}
})

axios请求接口遇到跨域问题

添加 withCredentials: true

post请求

 axios.post("http://ip:10000/api/v1/test", {
param1: 'test',
param2: 'test'
}, {
withCredentials: true
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err);
})

get请求

   axios.get("http://ip:10000/api/v1/test", {
params:{start:0,limit:10},
withCredentials: true
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err);
})


举报

相关推荐

LiveGBS GB28181流媒体服务

0 条评论