[XMLHttpRequest] GET request is not working in react-native android but working in react-native ios
var request = new XMLHttpRequest();
request.onreadystatechange = (e) => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.log('success', request.responseText);
} else {
console.warn('error');
}
};
request.open('GET', 'https://mywebsite.com/endpoint.php');
request.send();
my url is like : https://mywebsite.com/gen?method=getMethod&data={"userId" : "User2cc75dc3-44b0-45c3-4532-"}
Can you provide more details on the error you're getting?
With Get request am getting request.status == 0 and the error message is like java.net.URI: https://cloudapp.com/gen?method=getMethod&data={%22userId%22 : %22user2chhjej%22}
but with POST request am getting request.status == 200
What is the request.responseText when request.status == 0?
@prashanthnani - can you provide a real endpoint and exact code that we can test this with?
I am having the same problem here and trying to reach any get request from android (including things like www.google.com)
I happen to be using clojurescript and the function call for me is simply
(GET "http://www.google.com"
{:error-handler #(print "caused error")
:handler #(print "worked")})
There is nothing else that is needed. PS changing the same function above to simply POST works immediately. This was checked on a Nexus 5 as well as on AVD simulator.
@prashanthnani, @mackram did you check the ATS settings in Xcode project?
iOS requires HTTPS calls, unless you create exceptions as documented: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html#app-transport-security
Alternatively (but not recommended) add the following to your Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
This is however not recommended, and your app might be rejected from AppStore submission.
I'm seeing this for POSTs also. Could this be related to timeout somehow? Occurs when I introduce it.