Network error with axios and react native

前端 未结 7 2231
暗喜
暗喜 2021-01-19 13:35

I have created an API endpoint using the Django python framework that I host externally. I can access my endpoint from a browser (mydomain.com/endpoint/) and ve

相关标签:
7条回答
  • 2021-01-19 14:00

    If you are trying to call localhost on android simulator created with AVD, replacing localhost with 10.0.2.2 solved the issue for me.

    0 讨论(0)
  • 2021-01-19 14:05

    THE SOLUTION is: on Android you need to specify the file path with file:// as prefix. So do like this:

          const audio = {
            uri: 'file://' + this.recorder.fsPath,
            type: 'video/mp4',
            name: filename
          }
    
    0 讨论(0)
  • 2021-01-19 14:07

    It seems that unencrypted network requests are blocked by default in iOS, i.e. https will work, http will not.

    From the docs:

    By default, iOS will block any request that's not encrypted using SSL. If you need to fetch from a cleartext URL (one that begins with http) you will first need to add an App Transport Security exception.

    0 讨论(0)
  • 2021-01-19 14:07
    1. change from localhost to your ip(192.168.43.49)
    2. add http://

      http://192.168.43.49:3000/user/

    0 讨论(0)
  • 2021-01-19 14:11

    For me, the issue was because my Remote URL was incorrect. If you have the URL is a .env file, please crosscheck the naming and also ensure that it's prefixed with REACT_APP_ as react might not be able to find it if named otherwise.

    In the .env file Something like REACT_APP_BACKEND_API_URL=https://appurl/api can be accessed as const { REACT_APP_BACKEND_API_URL } = process.env;

    0 讨论(0)
  • 2021-01-19 14:21

    I was facing the same issue.

    i looked deeper and my

    endpoint url was not correct.

    By giving axios right exact url, my api worked like charm.

    Hope it may help anyone

    0 讨论(0)
提交回复
热议问题