【问题标题】:React-Native (Android) : Request failed with status code 403 - bscscan api testnetReact-Native (Android):请求失败,状态码为 403 - bscscan api testnet
【发布时间】:2021-09-22 03:38:58
【问题描述】:

请帮帮我,我一直被这个问题困扰:我在 React Native 上使用 Axios 发出请求 BSCSCAN-API-TESTNET,并且该请求仅在 iOS 中正常工作,但它不适用于Android(403 禁止响应)。

我的网址请求:https://api-testnet.bscscan.com/api?module=account&action=txlist&address=0x400ee0c820144c8bb559ace1ad75e5c13e750334&sort=desc&apikey=P3A263376TPJHKQ5IXUD4VHUNFQKDJB4G5 我更新了 apiKey,所以不要介意。

我的代码:(IOS:ok,android:抛出错误403)

try {
  const url =
    'https://api-testnet.bscscan.com/api?module=account&action=txlist&address=0x400ee0c820144c8bb559ace1ad75e5c13e750334&sort=desc&apikey=P3A263376TPJHKQ5IXUD4VHUNFQKDJB4G5';
  const response = await axios.get(url);
} catch (error) {
  throw error;
}

【问题讨论】:

    标签: android react-native axios http-status-code-403 bscscan


    【解决方案1】:

    设置用户代理帮助我解决了 403 问题。

    try {
          const url =
            'https://api-testnet.bscscan.com/api?module=account&action=txlist&address=0x400ee0c820144c8bb559ace1ad75e5c13e750334&sort=desc&apikey=P3A263376TPJHKQ5IXUD4VHUNFQKDJB4G5';
          const response = await axios.get(url, {headers: { "User-Agent": "Mozilla/5.0" }});
        } catch (error) {
          throw error;
        }
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 2019-11-27
    • 2020-04-05
    • 2020-11-15
    • 2020-04-25
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多