无法在三星电视(tizen 应用程序)中获取数据

问题描述 投票:0回答:1

我正在使用 Tizen studio 为三星电视制作一个应用程序。我从 API 获取数据,端点是简单的 GET 端点。相同的代码可以在其他浏览器中运行,或者如果我在浏览器中打开 Html 文件,API 会成功并得到响应。但在三星电视上,却得到了空洞的回应。 这是我正在使用的代码,

const apiUrl = 'https://example.com/apiGetEndpoint';

// Create a new XMLHttpRequest object
var xhr = new XMLHttpRequest();

// Configure the GET request
xhr.open('GET', apiUrl, true);


    // Set up a callback function to handle the response
    xhr.onreadystatechange = function () {
      // Check if the request is complete
      if (xhr.readyState === 4) {
        // Check if the response status is OK (status code 200)
        if (xhr.status === 200) {
          // Parse the response as JSON
//        var response = JSON.parse(xhr.responseText);
            console.log("XHR: ", xhr);
            var response = xhr.responseText;
          // Handle the response data
          console.log("Response: ", response);
        } else {
          // Handle the error (e.g., display an error message)
          console.error('Request failed with status:', xhr.status);
        }
      }
    };

// Send the GET request
xhr.send();

我真的很困惑,如果你知道解决方案,请告诉我。 预先感谢!

samsung-mobile tizen samsung-smart-tv tizen-web-app samsung
1个回答
0
投票

检查此链接。我想您的应用程序 config.xml 文件中缺少内容安全策略条目。

只需将您的网址(https://example.com/apiGetEndpoint)添加到配置中即可使其成为 connect-src。

<tizen:content-security-policy>default-src 'self'; connect-src 'self' https://example.com/apiGetEndpoint; style-src 'self' 'unsafe-inline';</tizen:content-security-policy>

如果以上方法无法解决您的问题,您还可以查看此页面了解更多可能的问题原因。

© www.soinside.com 2019 - 2024. All rights reserved.