1

first of all, I need to access my api in localhost I've tried everything but why it doesn't works (?)

first, I set my axios setup like this:

import axios from 'axios';

    export default axios.create({
        baseURL: 'http://localhost/github/xxxx/index.php/api',
        headers: {
            'Authorization': 'Basic username pass',
            'Content-Type': 'multipart/form-data'
        }
    });

but doesn't work,

Then I try this :

import axios from 'axios';

    export default axios.create({
        baseURL: 'http://192.xxx.xx.142/github/xxxx/index.php/api',
        headers: {
            'Authorization': 'Basic username pass',
            'Content-Type': 'multipart/form-data'
        }
    });

the baseURL is from IPv4 Address in ipconfig/all

but doesn't work, Then I've read about android emulator they said " if u want to use localhost then u need to set url to 10.0.2.2 like this :

import axios from 'axios';

    export default axios.create({
        baseURL: 'http://10.0.2.2/github/xxxx/index.php/api',
        headers: {
            'Authorization': 'Basic username pass',
            'Content-Type': 'multipart/form-data'
        }
    });

but still not working :(

and the error of message always like this : " Error while reading multipart response "

Error Message

how to fix this ? :(

I'm building the api using rest_api plugin codeigniter

thank you before

KaretNasiPadang
  • 117
  • 1
  • 2
  • 9

2 Answers2

0

Look like duplicate with : React Native Android Fetch failing on connection to local API

There is a "LAN" option to set on Expo.

HollyPony
  • 817
  • 9
  • 15
  • @KaretNasiPadang so, could you provide more information about your setup ? Android / iOS and if you used a guide ? According to the other post, there is many things to check : https://stackoverflow.com/a/54105349/5470616 – HollyPony Apr 11 '20 at 07:38
0

I've solved this by my self, after I search for the problem, the problem is you need setting localhost to static in apache ( httpd.conf ) , you need to add manualy your your local IP to there with port

KaretNasiPadang
  • 117
  • 1
  • 2
  • 9