Hello Developers,
thanks for being helpful on all-time.
I'm working on a project it's working fine on Web Navigator Chrome,
but when I build the Android App using react-native, I found that I can't send requests to my server with any of Axios or fetch.
catch is always send
Error : Network Error, but it's working fine with other servers here's some Screenshots :
I can't figure this out, so I expect some help from u guys.
Add this to your android/app/src/main/AndroidManifest.xml and below permission is used for accessing ConnectivityManager.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I had this same problem before on Android with React Native.
Here are the steps that I did when debugging it:
Try to use Postman to check if your endpoint is working.
I was using GraphQL so I tested using fetch and axios to see if it returns the same network error.
Test on iOS to see if it works or not.
After I did the above, since I deployed my API app on my own server. I pointed my graphql request to my public IP (http://xxx.xxx.xxx.xxx/graphql) and it works. You might need to add android:usesCleartextTraffic = "true" to your AndroidManifest.xml to make request to http url.
I finally figured out that it was a problem with my SSL certificate that was installed on my domain. I re-installed it back with proper certificate.pem and intermediate.pem and my problem is fixed.
Related
I'm trying to run an API call in React Native on Android with Expo using Axios, but I'm encountering a network error. I tried some solutions, but nothing seems to work. This is the error displayed in the console:
Network Error
at node_modules\\axios\\lib\\core\\AxiosError.js:3:0in \<global\>
at node_modules\\axios\\lib\\adapters\\xhr.js:138:8 in handleAbort
at node_modules\\event-target-shim\\dist\\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
at node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:647:10 in setReadyState
at node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:396:6 in didCompleteResponse
at node_modules\\react-native\\Libraries\\vendor\\emitter_EventEmitter.js:150:10 in EventEmitter#emit
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:417:4 in callFunction
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:114:6 in guard$argument_0
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:368:10 in guard
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:113:4 in callFunctionReturnFlushedQueue
I tried changing the localhost in the API link to my IP address, as well as to 10.0.2.2, but nothing worked. I checked my internet permission in AndroidManifest and made some other permission changes to the file, but nothing seemed to resolve it. I hope to find a solution to the problem soon.
if you are using a tool like expo go, [axiosError: Network error] is simply an error saying that the api you provided may not be reached.
so if you want to pull data from a local storage instead of cloud storage ... you may create a server like for example php artisan serve then create an Ngrok server for that server , afterwards take the link you received from the ngrok then use it as your new API endpoint
i m the same problem. you found solution l
I have an ionic app that when I run that on iOS then it works perfectly fine but when I run that on Android I get this error
Http failure response for (unknown url): 0 Unknown Error
Any reason I am getting this one? I have allowed CORS on server side as it is working on iOS devices.
Any help?
EDIT
This is what I have in my app.js file
const cors = require('cors');
And then I simply use it with default options.
app.use(cors());
If you are using localhost, change it to the IP address of the localhost. Android doesn't seems to support it where iOS do.
Try actual host name in case it didn't work too.
First you dont need CORS to call API from your android device.
Second probably your server is not accepting your request. If you are using Cloud then your server must accept request from any IP. There must be a option for allow IP address, place there from 0.0.0.1 to 254.254.254.254 so that each and every user can call your API.
Third you need to allow origin from your config.xml and also in header for CROS request. Check your API header and config file.
And fourth If your service is running under http then it will also could be the problem. Secure your service by adding SSL certificate. This could fix your problem.
We had experienced the same Error several times in our App. In our case it was a problem with the headers of the request and also a CORS problem on the serverside.
Are you able to reproduce this error in the browser if you emulate a android device? Then you could compare them with the headers of the iOS request.
Or you can try to log the incoming requests on the server-side to see if the requests reach the server and what headers are set.
Hope my ideas help :)
The solution is to add NODE_TLS_REJECT_UNAUTHORIZED=0 to your environment to disable the SSL verification in Node.js.
Note : You should only set this in development, Don't do this in production
EDIT
In that case it indicates that CORS has not been properly setup on your server. Go through the issue here
I've created Cordova Android app, and I'm facing this issue:
When on 3G/4G, whenever I try to make request towards my server I get the error:
ERR_TUNNEL_CONNECTION_FAILED.
When I am on WIFI everything works fine. This is not happening on all Android devices, I am facing this issue on Samsung Galaxy A5 (nd some other Androids).
I've discovered that if we use HTTP instead of HTTPS everything is fine.
Also according to https://www.sslshopper.com/ssl-checker.html
and
https://www.digicert.com/help/
everything seems to be fine with our SSL cert.
How can we solve this issue?
This usually happens because your provider is configuring a proxy in your device.
Try checking your current APN setting and deleting the fields proxy and port from it.
This also can be caused if you are using a port different from 443
I wonder if you have found your answer or not, but still want to post answer for others looking for the solution: Note that Cordova doesn't allow https calls to Servers with untrusted ssl certificate installed on them. You can ignore this error and continue by making a small change in a cordova file.
Open “\cordova\platforms\android\CordovaLib\src\org\apache\cordova\
CordovaWebViewClient.java”. In 'onReceivedSslError' method, comment
the else part and add handler.proceed() instead.
This issues happens with mobile data connection because the default Access Point that came with carrier generally have proxy that will not allowing SSL Tunneling. All you have to do is to set Proxy and Port to nothing.
Also ensure to use only port 443 for HTTPS.
I have a jHipster project with Jwt Authentication but I can't get it to work outside de webapp. I'm currently developping a Android application and the authentication process get harder than I expected.
Basically I'm sending the parameters of the LoginDTO, to UserJwtController#authorize ('/api/authenticate'). At first I was getting Unauthorized, both on Android or Postman (I'm using it to test the requests).
If I change the '/api' to permitAll, I'm getting 405, Request method 'POST' not supported.
EDIT
It was a wrong typo on Android :/
It works fine for me against /api/authenticate, so either you use wrong URL (e.g. /api/authorize) or your JSON payload is wrong. The only issue you could have is with CORS. You should consider testing with curl as it is easier than PostMan for reporting here what you really do and also the curl options are already built for you in JHipster swagger page.
I have started building simple Todo app in Ionic 1 and I discovered a problem with Origin header. (CORS related)
If i run
ionic serve
everything works fine in browser and i can make requests to my REST API on apache(tomcat). But when build my app for android or even in ionic viewer, all requests fail. Using a chrome debugger I managed to locate the problem.
Native app sends header (tested only on android)
Origin: file://
which causes my server to deny requests. Seems to me that it should send correct Origin header with host. Screenshot with more details is attached below.
What can I do about that?
Found related topic here: CORS, Cordova, AngularJs $http and file:// confusion
Already posted here, with no luck: https://forum.ionicframework.com/t/native-app-is-sending-header-origin-file-which-causes-problems/62388/1
EDIT: Problem occurs when post, if I run ionic starter (tabs) template with only $http.post('http://myapp.com/apiv1/device') added to controller.
Try adding the following to your allowed origin request: "file://* filesystem: "
I had the same problem with <iframes> in Ionic and I fix it adding:
Header set Content-Security-Policy "...; frame-ancestors 'self' file://* file://*/* filesystem: http://localhost:*;"
It seems that the problem comes from the server (specifically from Tomcat).
According to this bug:
https://bz.apache.org/bugzilla/show_bug.cgi?id=60008
The default CORS filter provided by Tomcat (instances/shared/conf/web.xml) doesn't allow POST requests and returns 403.
The problem is solved from Tomcat version 8.0.37, so upgrading the server should solve your problem.
Regards.
I've came across this last week. I had to make POST request to JIRA api and I wasn't able to change server configuration.
Probably the easiest way is to make your own android plugin which sends POST request. If you send POST request from plugin, there is no Origin: file:// header and everything works fine. The plugin was like 2-3 hours of work.