【问题标题】:react native 403 permission error from php api on wamp server来自 wamp 服务器上的 php api 的本机 403 权限错误反应
【发布时间】:2021-09-26 12:46:07
【问题描述】:

react native error

import React, { Component } from 'react';
import { ActivityIndicator, FlatList, Text, View } from 'react-native';

export default class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      data: [],
      isLoading: true
    };
  }

  async getMovies() {
    try {
      const response = await fetch('http://192.168.1.6:80/p4Lite/Sept2021/react_backend/index.php');
      const json = await response.json();
      this.setState({ data: json });
    } catch (error) {
      console.log(error);
    } finally {
      this.setState({ isLoading: false });
    }
  }

  componentDidMount() {
    this.getMovies();
  }

  render() {
    const { data, isLoading } = this.state;

    return (
      <View style={{ flex: 1, padding: 24 }}>
        {isLoading ? <ActivityIndicator/> : (
          <FlatList
            data={data}
            keyExtractor={({ id }, index) => id}
            renderItem={({ item }) => (
              <Text>{item.name}, {item.email}</Text>
            )}
          />
        )}
      </View>
    );
  }
};
以上是我的 app.js 文件代码。它在网络上运行良好,但在我的 android 手机上使用 expo go 时显示错误。我尝试了各种方法,但直到现在都喜欢解决方案。我正在本地主机上工作。

【问题讨论】:

  • 你能发布你得到的任何错误日志吗?
  • 请点击(react native error)查看错误截图。

标签: php react-native http-status-code-403


【解决方案1】:

在你的 API 相关文件夹上试试这个

sudo chmod -R -f 777 /path/to/your/file/or/directory

【讨论】:

  • Thanyou 通过您的回答大致了解了这个问题
  • 如果有帮助,请接受并投票:) @SilverMoon
【解决方案2】:

403 错误意味着您提出的请求被禁止。通常在未输入所需密码时收到。

很可能,您的 API 需要密码,而这不是由代码提供的,服务器代码配置错误,或者服务器没有显示结果的正确权限。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

【讨论】:

    【解决方案3】:

    通过更改它的一些工作原理: Require local to Require all grant in httpd-vhosts.conf

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 2015-06-15
    • 2017-07-17
    • 2011-07-12
    • 2022-12-29
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    相关资源
    最近更新 更多