'(Flutter) HTTPClient Invalid argument(s): No host specified in URI
Currently working on a little app that allows users to view a database stored on Heroku, however I am running into the aforementioned issue when using the database's URL: ".herokuapp.com/api/".
var client = createHttpClient();
var response = await client.read('<example>.herokuapp.com/api/<data>');
List data = JSON.decode(response);
Heroku doesn't seem to use HTTP(S) nor www, the latter of which I believe to be the issue.
Does anyone know how I can bypass or resolve this issue?
Solution 1:[1]
I know this is an old problem but I just stumbled into this problem and fixed it by adding an "http://"
before the URL.
Solution 2:[2]
One of the problem is not having "http://" before your API URL;
SOLUTION Add "http://" before your API URL example API_URL = "api.openweathermap.org/data/2.5/weather?q={city%20name}&appid={your%20api%20key}"
By adding "http://" it becomes "http://api.openweathermap.org/data/2.5/weather?q={city%20name}&appid={your%20api%20key}"
Solution 3:[3]
If you still get this issue in latest versions of flutter, try to check the following things.
Previously uri was in String type. Now its in Uri type for the http requests.
If we try to use the url as
String urlPath = '<example>.herokuapp.com/api/<data>';
client.read(Uri(path: urlPath));
We will get the exception as No host specified in URI
This can be solved by using parse method in Uri class
client.read(Uri.parse(urlPath));
It solves the issue.
Solution 4:[4]
This works for me
child: CircleAvatar(
backgroundImage: imageFile != null
? FileImage(imageFile)
: imgUrl.isNotEmpty
? NetworkImage(imgUrl)
: null,),
Solution 5:[5]
This has worked for me
CachedNetworkImage(imageUrl: 'https://example.com/'+item['image'],),
Solution 6:[6]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ravindra S. Patil |
Solution 2 | eclat_soft |
Solution 3 | Sankar Arumugam |
Solution 4 | Kaushal Kishore |
Solution 5 | Kenneth kipngok kipruyot |
Solution 6 | Kiran Stha |