0

I try to connect my api with nativescript when i run in android emulator axios get all data from backend but when i try to run on actual mobile using tns preview or tns preview --bundle axios not working its give me null value

LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(Page)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(Page(3), ActionBar(4))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(ActionBar)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(gridlayout)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(Frame)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(stacklayout)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(textfield)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(6), Label(7))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(label)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(stacklayout)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(8), TextField(9))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(button)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(8), Button(10))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(StackLayout(6), StackLayout(8))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(GridLayout(5), StackLayout(6))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateComment()
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> CreateElement(ListView)
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(Page(3), GridLayout(5))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(ListView(11), Placeholder(13))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(GridLayout(5), ListView(11))
LOG from device Tarang shah: {NSVue (Vue: 2.6.11 | NSVue: 2.6.4)} -> AppendChild(Frame(2), Page(3))
**LOG from device Tarang shah: null**

Any one know how to solve this issue and my backend api store on serve not in local device

My code for axios

axios({ method: "GET", "url": "http://api.sinhgadcollegeofscience.com/api/todos" }).then(result => {
                console.log(result.data)
                commit('setTodos', result.data)
            }, error => {       
                console.log('errorsssss')
            });
Rob
  • 14,746
  • 28
  • 47
  • 65

1 Answers1

1

You are making a clearText request (http://...) which is disabled by default since android API 28 I believe.

If you can, try using a https connection. Otherwise you can enable clearText traffic in the AndroidManifest.xml

<application
 <!-- ... -->
 android:usesCleartextTraffic="true"
 <!-- ... -->
</application>

After making the change, delete the platforms folder, and rebuild the app.

More detailed information can be found here: Android 8: Cleartext HTTP traffic not permitted

Igor R.
  • 897
  • 5
  • 14
  • Thank you for replay i try but its didn't work on mobile (have andriod 10) and axios send null value when i try to debug tns its working properly but not working on actual device – tarang shah Jun 05 '20 at 05:54
  • Double check that you can access the url from the mobile phone - for example try opening it in the browser on the actual device and see if it can connect. – Igor R. Jun 05 '20 at 18:06