最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Not able to hit api in React Native only in Android (IOS , Postman Working) - Stack Overflow

programmeradmin0浏览0评论

This is the error i am getting : -

Below is the code : -

const login = async () => {
    console.log("running....")
    try {
      console.log("try block")
      const response = await fetch(";, {
        method: 'POST',
        headers: 
        { 
          Accept : "application/json",
          'Content-Type': 'application/json' 
        },
        body: JSON.stringify({ email: "[email protected]", }),
      });
  
      console.log("Response Status:", response.status);
      const jsonResponse = await response.json();
      console.log("Response:", jsonResponse);
    } catch (error) {
      console.error("Error:", error);
    }
  };

also set the file (network_security_config.xml)

`<!-- react native -->
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">;/domain>
    </domain-config>
    <!-- <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config> -->
</network-security-config>`

AndroidMAnifest.xml

So i have tried

  1. changes AndroidMAnifest.xml (check above image)
  2. postman working fine
  3. other api is working

Above is dummy api but the problem is other apis i am able to get response just the main api not working.

发布评论

评论列表(0)

  1. 暂无评论