How to call axios/api call in Nativescript application

后端 未结 2 1261
猫巷女王i
猫巷女王i 2021-02-04 16:37

I\'m trying to build a small application on Nativescript-vue where I\'m having backend laravel framework for api calls which needs to be called to get

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 16:46

    I tested the exact same project you have shared in Github with Android 8.0, it works perfectly fine. The axios call hits the error block as the response status (error.response.status) is 401 and data (error.response.data) returns the exact same response you see from Postman.

    If you are using Android 9 or later it might fail as you haven't enabled useCleartextTraffic on your application tag in the AndroidManifest.xml.

    With iOS also it would fail as you haven't enabled app transport security. Just to allow all Http communication within your app, you have to add the following key to your info.plist

    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
    
    

    In case if you want to allow only specific domains, then use NSExceptionDomains key and list the endpoints.

提交回复
热议问题