Fetch() Doing Get Instead of Post on React-Native (iOS)

fetch() doing GET instead of POST on react-native (iOS)

After further digging, it was definitely an issue with the API + fetch. I was missing a slash at the end of the URL and the API issued a 301, that fetch didn't handle correctly. So I don't know if there is something to fix in the fetch function (and underlying mechanisms) but this fixed my issue :)

React Native - Fetch POST not working

I would guess the response you are receiving is in HTML. Try:

 console.warn(xhr.responseText)



Then look at the response.

Also, IOS requires HTTPS.

Edit: Possible duplicate: "SyntaxError: Unexpected token < in JSON at position 0" in React App

Fetch doesn't work in React Native ios

The reason for this problem is that: iOS does not allow http requests by default, only https. If you need to do this with http, just change your info.plist:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

React Native Post Request via Fetch throws Network Request Failed

This React Native's error is rather useless, so you need to get the actual underlying error first. The most straightforward way is to write a small native program that would just perform the same query using HttpsURLConnection.

For me the actual error was java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
which has a well known solution: https://developer.android.com/training/articles/security-ssl.html#MissingCa

This is quite likely your case also, given that the browsers and Postman have no problem with the request. To check it run openssl s_client -connect XXreachable-domainXX.de:443 -showcerts. If there are certificate errors, fix them first, it could spare you time writing the native program.

Edit: actually the easiest way to see all underlying android errors for react native is simply running 'adb logcat' in terminal



Related Topics



Leave a reply



Submit