I'm trying to receive a get request using Flutter and HttpClient.
This is complete code in what I'm trying to accomplish.
getSuggest() async {
try {
var httpClient = new HttpClient();
var uri = new Uri.http(
'http://autocomplete.geocoder.api.here.com', '/6.2/suggest.json', {
'app_id': 'APP_ID',
'app_code': 'APP_CODE',
'query': '123 Main Street',
'country': 'USA',
'language': 'en',
});
var request = await httpClient.getUrl(uri);
var response = await request.close();
var responseBody = await response.transform(Utf8Decoder()).join();
Map data = jsonDecode(responseBody);
print(data);
} catch (error) {
print(error);
}
}
And I'm using
import 'dart:io';
import 'dart:convert';
But my code always gets sent to the print(error)
and the error that gets printed is
FormatException: Invalid radix-10 number
Any ideas?
Thanks!!
The problem is the scheme. You don't have to set it in
Uri.http
orUri.https
methods, it is set automatically, so change with the following:And I suggest using http package and do something like that:
and use its
http client
if you need to set much more things (e.g.User Agents
).