【发布时间】:2020-04-11 06:01:27
【问题描述】:
首先, 我需要在 localhost 中访问我的 api 我已经尝试了所有方法,但为什么它不起作用(?)
首先,我将我的 axios 设置如下:
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'
}
});
但不起作用,
那我试试这个:
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'
}
});
baseURL 来自 ipconfig/all 中的 IPv4 地址
但不起作用,然后我阅读了有关 android 模拟器的信息 他们说“如果你想使用 localhost 那么你需要将 url 设置为 10.0.2.2 像这样:
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'
}
});
但仍然无法正常工作:(
消息的错误总是这样: "读取多部分响应时出错"
如何解决这个问题? :(
我正在使用 rest_api 插件 codeigniter 构建 api
谢谢你
【问题讨论】:
-
stackoverflow.com/a/43277765/9009196 number 2 为我工作
标签: reactjs react-native