首页 > 解决方案 > 反应本机小米手机 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.");
});

代码的图像 代码的图像

关联

标签: androidreact-nativemobilemobile-applicationxiaomi

解决方案


我不确定是什么问题,但我遇到了与 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);
      });

推荐阅读