insta360 X2 OSC(开放球形相机)预检角度的 API 调用失败。

huangapple go评论62阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月10日 12:44:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定