uni-app request:fail abort statusCode:-1 Expected URL scheme 'http' or 'https' but was 'file'

uni-app request:fail abort statusCode:-1 Expected URL scheme ‘http’ or ‘https’ but was ‘file’

操作步骤:

  • 复线

预期结果:

  • 预期

实际结果:

  • 实际

bug描述:

H5端调试正常,android基座运行就出现这个问题,打包后也是这样,电脑和手机的ip地址都一样,不知道为什么还是报这个错误

image

信息类别 详细信息
产品分类 uniapp/App
PC开发环境 Windows
PC开发环境版本 联想y7000
HBuilderX类型 正式
HBuilderX版本 3.99
手机系统 Android
手机系统版本 Android 10
手机厂商 红米
手机机型 红米note9pro
页面类型 vue
vue版本 vue2
打包方式 云端
项目创建方式 HBuilderX

更多关于uni-app request:fail abort statusCode:-1 Expected URL scheme 'http' or 'https' but was 'file'的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

看看是不是某个接口页面加载就调用了,这时候可能项目还没完全起来,还没连接到服务器,接口就被调用了所以报错了,可以试试先把onload或者onshow里的接口调用方法注释掉,然后运行下看看还报错吗,如果是这个问题,可以加个定时器同时在页面里加个加载的过渡动画,我碰到过这个问题,是Android设备开机自启app,还没完全加载的时候就调用了接口导致的,不知道你和我的情况一样不~

更多关于uni-app request:fail abort statusCode:-1 Expected URL scheme 'http' or 'https' but was 'file'的实战教程也可以访问 https://www.itying.com/category-93-b0.html


The error message you’re encountering, request:fail abort statusCode:-1 Expected URL scheme 'http' or 'https' but was 'file', indicates that the request you’re trying to make in your uni-app is using a file:// URL scheme instead of the expected http:// or https://.

Possible Causes and Solutions:

  1. Incorrect URL:

    • Ensure that the URL you’re trying to request is correctly formatted and starts with http:// or https://.
    • Example:
      uni.request({
        url: 'https://example.com/api',
        method: 'GET',
        success: (res) => {
          console.log(res.data);
        },
        fail: (err) => {
          console.error(err);
        }
      });
      
  2. Local File Access:

    • If you’re trying to access a local file, ensure that you’re using the correct path and that the file is accessible. For local files, you might need to use a different method, such as uni.getFileSystemManager() or uni.chooseImage().
  3. Network Permissions:

    • Ensure that your app has the necessary network permissions. In some environments, you might need to configure permissions to allow network requests.
  4. Platform-Specific Issues:

    • If you’re testing on a specific platform (e.g., H5, WeChat Mini Program, etc.), ensure that the platform supports the type of request you’re trying to make. Some platforms may have restrictions on certain types of requests.
  5. Cross-Origin Issues:

    • If you’re making a request to a different domain, ensure that the server supports cross-origin requests (CORS). You might need to configure the server to allow requests from your app’s domain.
  6. SSL/TLS Issues:

    • If you’re using https://, ensure that the server has a valid SSL/TLS certificate. Some platforms may reject requests to servers with invalid or self-signed certificates.

Example of a Correct Request:

uni.request({
  url: 'https://jsonplaceholder.typicode.com/posts',
  method: 'GET',
  success: (res) => {
    console.log(res.data);
  },
  fail: (err) => {
    console.error(err);
  }
});
回到顶部