首页 > 解决方案 > NativeScript HTTP 获取请求不起作用。安卓版本问题?

问题描述

我一直在研究 node.js 后端应用程序。现在我想开始对前端进行编程,但我在执行 HTTP 请求时遇到了困难。我有一个用于测试的物理平板电脑三星 Galaxy Tab Active2,但简单的 GET 请求在这款装有 Android 版本 9 的平板电脑上不起作用。

我尝试在 Android 8.1 上使用 HTTP 请求运行完全相同的应用程序,并且它工作正常。我正在返回内容。

    getTest() {
        console.log('test')
      httpModule
        .request({
          url: "http://XXX.XXX.XXX.XXX:8080/XXX/XXX",
          method: "GET"
        })
        .then(
          response => {
            // Content property of the response is HttpContent
            // The toString method allows you to get the response body as string.
            const str = response.content.toString();
            const head = response.headers.toString();
            console.log("Content:" + str + " Header: " + head );
            // The toJSON method allows you to parse the received content to JSON object
            // var obj = response.content.toJSON();
            // The toImage method allows you to get the response body as ImageSource.
            // var img = response.content.toImage();
          },
          e => {}
        );
    }

版本 8.1 模拟器为我提供了内容,但我在 Android 版本 9 上运行的物理平板电脑仅将输出“测试”提供给控制台。它不会连接到我的后端(我配置了一个记录器,它在请求中提供输出)。

标签: androidhttpgetrequestnativescript

解决方案


推荐阅读