英文:
insta360 X2 OSC (open spherical camera) api call failed in preflight angular
问题
I am trying to send get call to the camera http://192.168.42.1/osc/info
from angular ionic application . This request stuck in preflight. I suspect this might be the CORS issue and I had tried below code but this did not work.
getinfo()
{
const headers =new HttpHeaders({
'X-XSRF-Protected': '1',
'Content-Type': 'application/json;charset=utf-8',
'Accept': 'application/json',
'Access-Control-Allow-Headers':'*',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'GET'
})
this.http.get("http://192.168.42.1/osc/info",{headers: headers}).subscribe(data => {
console.log("Result:" + data);
return data;
}, error => {
console.log('Error'+ error);
});
above get method is getting called in another ts file like
this.results = this.servicename.getinfo();
above result I am displaying in html page
I also followed the INSTA360 OSC API LINK and passed the mentioned headers except content length as this is get call.
This same reqeust when I hit from the browser or from postman then it works and give the results. I also tried to change the host to 192.168.42.1:6666 but not get expected result.
To avoid CORS error I change the Content type to text/plain but still got same issue
Is there anything I am missing.
英文:
I am trying to send get call to the camera http://192.168.42.1/osc/info
from angular ionic application . This request stuck in preflight. I suspect this might be the CORS issue and I had tried below code but this did not work.
getinfo()
{
const headers =new HttpHeaders({
'X-XSRF-Protected': '1',
'Content-Type': 'application/json;charset=utf-8',
'Accept': 'application/json',
'Access-Control-Allow-Headers':'*',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'GET'
})
this.http.get("http://192.168.42.1/osc/info",{headers: headers}).subscribe(data => {
console.log("Result:" + data);
return data;
}, error => {
console.log('Error'+ error);
});
above get method is getting called in another ts file like
this.results = this.servicename.getinfo();
above result I am displaying in html page
I also followed the INSTA360 OSC API LINK and passed the mentioned headers except content length as this is get call.
This same reqeust when I hit from the browser or from postman then it works and give the results. I also tried to change the host to 192.168.42.1:6666 but not get expected result.
To avoid CORS error I change the Content type to text/plain but still got same issue
Is there anything I am missing.
答案1
得分: 1
使用CapacitorHttp插件使用本机http而不是angular。这就是我解决CORS问题的方式。
英文:
Use CapacitorHttp plugin to use native http instead of angular. This is how I got around the CORs issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论