Getting this error while calling api.
Sometimes I receive response occasionally. I tested the api using postman it is working perfectly fine.
Version: http: ^0.11.3+16
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (24807): SocketException: Failed host lookup: 'api.xyz.com' (OS Error: No address associated with hostname, errno = 7)
E/flutter (24807): #0 IOClient.send (package:http/src/io_client.dart:30:23)
E/flutter (24807): <asynchronous suspension>
E/flutter (24807): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:171:38)
E/flutter (24807): <asynchronous suspension>
E/flutter (24807): #2 BaseClient.post (package:http/src/base_client.dart:56:5)
E/flutter (24807): #3 post.<anonymous closure> (package:http/http.dart:70:34)
E/flutter (24807): #4 _withClient (package:http/http.dart:167:20)
E/flutter (24807): <asynchronous suspension>
E/flutter (24807): #5 post (package:http/http.dart:70:3)
E/flutter (24807): #6 NetworkUtil.post (package:ddictor/utils/network_util.dart:29:10)
E/flutter (24807): #7 loginUser (package:ddictor/utils/api.dart:23:16)
post method inside network_util file
`
Future
return http
.post(url, body: body, headers, encoding: encoding)
.then((http.Response response) {
final String res = response.body;
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode > 400 || json == null) {
throw new Exception("Error while fetching data");
}
return _decoder.convert(res);
});
}
The errors Failed host lookup: 'api.xyz.com' and OS Error: No address associated with hostname usually mean that your DNS lookup fails.
As hinted by OS Error this is usually a system-level error and nothing specific to http or Dart.
To diagnose this on your system you can try check e.g. your browser can DNS resolve the host in question. And/or if you're on a Mac/Linux system you might be able to run dig api.xyz.com to see if that resolves.
When doing anything network, or I/O in general, it's a good idea to program very defensively and assume the I/O can sporadically fail or time out.
You can try see if you can make your code degrade more gracefully in cases when e.g. DNS isn't working as expected.
I'll go ahead and close this issue since I don't think there's anything to be done in http
Anyone facing this issue: try adding <uses-permission android:name="android.permission.INTERNET" /> to your AndroidManifest.xml.
thank you, this worked for me
I had the same error. In my case it was because the emulator of the phone that I am using does not have access to the internet.
Run the application on a physical mobile device and it worked immediately.
Solution connect the emulator to the internet.
I think we need to add message that you need to add internet permission in Install section of doc
I think we need to add message that you need to add internet permission in Install section of doc
Please +1 and follow https://github.com/flutter/flutter/issues/29688
If we have some flutter docs to point to from this README we can do that.
I have the same issue when run in release mode,but it is ok when debug mode !
@Derkin - please raise the issue at flutter/flutter#29688
This isn't a problem that can be solved in this package.
Hi,
This error is because if your Simulator or Your phone doesn't connect to the Internet.
Anyone facing this issue: try adding
<uses-permission android:name="android.permission.INTERNET" />to your AndroidManifest.xml.
@gurgenDP pls help me this way dont solve my problem
flutter/flutter/#43357
Just ran into this issue. After about half an hour I finally figured out that it was because I had my VPN on..
I have the same issue when run in release mode,but it is ok when debug mode !
i have same issue with my app . So have u figured it out now???
@jawale204 - please raise the issue at flutter/flutter#29688
This isn't a problem that can be solved in this package.
I have the same issue when run in release mode,but it is ok when debug mode !
i have same issue with my app . So have u figured it out now???
This error is because if your Simulator or Your phone doesn't connect to the Internet.
I made new minor sdk updates, upgraded the http package, closed the emulator and re-opened it, and stopped the application and re-compiled the problem was fixed.
The errors
Failed host lookup: 'api.xyz.com'andOS Error: No address associated with hostnameusually mean that your DNS lookup fails.
As hinted byOS Errorthis is usually a system-level error and nothing specific tohttpor Dart.To diagnose this on your system you can try check e.g. your browser can DNS resolve the host in question. And/or if you're on a Mac/Linux system you might be able to run
dig api.xyz.comto see if that resolves.When doing anything network, or I/O in general, it's a good idea to program very defensively and assume the I/O can sporadically fail or time out.
You can try see if you can make your code degrade more gracefully in cases when e.g. DNS isn't working as expected.I'll go ahead and close this issue since I don't think there's anything to be done in
http
that was valuable insight, thanks @cskau-g man. I was worried about this issue.
It was DNS, I was messing with my DNS settings.
people kept spamming about the missing Internet Permission. That wasn't my case.
It was hard to find this info. I'll set the DNS to default settings and see if it's resolved.
thanks again! 👍🤝
I had the same error. In my case it was because the emulator of the phone that I am using does not have access to the internet.
Run the application on a physical mobile device and it worked immediately.
Solution connect the emulator to the internet.
This solved the issue for me. Thanks a lot!
@jawale204 - please raise the issue at flutter/flutter#29688
This isn't a problem that can be solved in this package.
step 1
add
to you androidmanifest, if done,
step 2
connect your emulator to a internet, if you cant use in on your physical device
Anyone facing this issue: try adding
<uses-permission android:name="android.permission.INTERNET" />to your AndroidManifest.xml.
HAVE TRIED THE ABOVE BUT THE SAME ERROR EXISTS PLS HELP....
I am also facing the same error after doing all the steps mentioned above. Please suggest.
Failed Host Lookup error occurs when their is no internet connection in the AVD in the laptop...... Suggestion is to close the AVD, check your internet connection and then open your AVD and then run again......
Also if their is a problem in the API itself the. This error might occur..........
That's how I did solve it...
Just restart the emulator that's it
On Tue, Dec 15, 2020, 8:15 AM AYAN BHATTACHARYA notifications@github.com
wrote:
That's how I did solve it...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/dart-lang/http/issues/185#issuecomment-745015911, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AODLGO5DP76Y5W2BSK5ROPTSU3EWBANCNFSM4FLL2Q5Q
.
Most helpful comment
Anyone facing this issue: try adding
<uses-permission android:name="android.permission.INTERNET" />to your AndroidManifest.xml.