Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  51] [ 6]  / answers: 1 / hits: 5443  / 4 Years ago, thu, january 16, 2020, 12:00:00

I was building my react native application and using backend URL as http://123.123.123.123:port/ and everything was working fine while in development. but when I built my app and installed it on an android device it wouldn't work and I remember someone telling me that android by default only lets https request. so I changed the URL to the one that the web app is using which is https://example.com/api/... (not self-signed TSL certificate) and now the android can send requests but they all return as Network Errors (when built and when running on an emulator), but it works fine on iOS simulator. I'm new to app development and can't find any solutions online. Maybe there is an option that I'm missing?



My axios setup, that is sending the requests:



const customAxios = axios.create({
baseURL: baseURL,
timeout: 6000,
});

...

const response = await customAxios.post('/login', {
email,
password,
});


Error stack:



Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:81)
at XMLHttpRequest.dispatchEvent (event-target-shim.js:818)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:574)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:388)
at XMLHttpRequest.js:501
at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
at MessageQueue.__callFunction (MessageQueue.js:436)
at MessageQueue.js:111
at MessageQueue.__guard (MessageQueue.js:384)


The https URL is working on ios and web applications


More From » android

 Answers
7

In your manifest file add android:usesCleartextTraffic=true inside application tag.



<application
xmlns:tools=http://schemas.android.com/tools
tools:replace=android:allowBackup
android:name=.MainApplication
android:label=@string/app_name
android:icon=@mipmap/ic_launcher
android:roundIcon=@mipmap/ic_launcher_round
android:usesCleartextTraffic=true>...
</application>

[#5037] Monday, January 13, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rocioblancac

Total Points: 699
Total Questions: 96
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
rocioblancac questions
;