android - 反应本机小米手机 axios 不工作
问题描述
我们开发了一个带有 react native 的应用程序。我将在下面留下应用程序的链接,我不知道这是否被禁止。我使用 axios 提取数据,它适用于所有 android 设备。但它不适用于小米手机。我找不到原因。
const api = "apiadress/deneme.php?lesid="+getLessonId;
axios.get(api).then((response)=>{
db.transaction((tx) => {
tx.executeSql('UPDATE lessons SET downloaded=? WHERE id=?', ['1',getLessonId]);
});
response.data.map((item) => {
db.transaction((tx) => {
tx.executeSql('INSERT INTO questions (questionname,lessonname,answerbame,aoptionname,boptionname,coptionname,doptionname,eoptionname,lessonid,oldidq) VALUES (?,?,?,?,?,?,?,?,?,?)',
[item.QuestionName,item.LessonName,item.AnswerName,item.AOption,item.BOption,item.COption,item.DOption,item.EOption,item.id,item.Id]);
});
});
console.log("Tüm sorular başarıyla kayıt edildi.");
});
代码的图像
解决方案
我不确定是什么问题,但我遇到了与 axios 类似的问题(部署后服务器请求不起作用)
您应该考虑离开 axios 并尝试使用 fetch:
邮政:
fetch('http://mywebsite.com/endpoint/', {
method: "POST",
headers: {
// Authorization: "Bearer " + Token,
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
// sending data userID username, password, etc
}),
})
.then((response) => response.json())
.then((responseJson) => {
// Response will here
})
.catch((error) => {
alert(error);
});
得到:
fetch('http://mywebsite.com/endpoint/', {
method: "GET",
headers: {
// Authorization: "Bearer " + Token,
// OR USER name PASSworrd
Accept: 'application/json',
'Content-Type': 'application/json'
},
})
.then((response) => response.json())
.then((responseJson) => {
// Response will here
})
.catch((error) => {
alert(error);
});
推荐阅读
- tfs - 为什么 TFS 预测工具会忽略活动的、已解决的项目?
- python - 重叠和接触的多边形的 GeoPandas.overlay() 缺少结果(how='intersection')
- dependencies - 有没有办法在 Program.exe.manifest 的 UMMM(无人参与的 Make My Manifest)创建中指定 File Name=?
- circuit-sdk - 在同一主题框中添加两条带有电路休息 api 的单独消息
- typescript - TypeScript 中的“:”是什么意思?
- c# - 删除datagridview选中的行C#
- postgresql - 两个表之间是否存在约束以确保一个数字包含在一个范围内?
- flutter - 带有单个标签的颤振范围滑块
- python - Python folium 地图开发
- botframework - 在 msteams 中安装 bot 时在弹出窗口中显示自适应卡(使用选项卡配置 url)