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
Adding an Skscene to a Uiviewcontroller
How Is a Swift Cgvector Created with Dx and Dy (Derivative)
Uicollectionviewcompositionallayout - Center Items in Sections or Groups
Googlemap API Gives Wrong Coordinates for Direction Between Two Points
No Such Module Iqkeyboardmanagerswift
-Webkit-Overflow-Scrolling: Touch' Broken for Initially Offscreen Elements in iOS7
iOS 7 Weather App Expand/Collapse Transition
Preventing Erasure of User Data While Upgrading iOS Application via Itunes
Strange Custom Background Color on Uipickerview Swift
How to Make a Reusable Tableview for Different Screens in the Same Application
iOS 8 Code Working on iPhone 5S But Not iPhone 5
How to Set UIactivityviewcontroller Gmail Share Subject Different Than Body
Why Wkwebview Doesn't Display Videos? - Swift 3
Uiactivityviewcontroller Subject Not Working for Outlook
How to Add a Lock Screen Widget (Requiring iOS 16) and Still Support iOS 15
How to Send Push Notification to Apns from iOS Device
How to Launch IPA File in iOS 10 Real Device Using Appium 1.6.0