Context
I have an API (http) that i can access with the GET method via Postman without any issue. I wanted to fetch data from this API for my flutter app using the http package.
Issue
While making the network request, with http.get() method of the http package, like below, I couldn't fetch data from the API.
Future<Product> fetchProducts(String barcodeId) async {
var vPath = '/products/' + barcodeId;
var vUri = new Uri(
scheme: 'http',
host: 'product.acirfa.tech',
port: 3000,
path: vPath,
);
// /products/224213463241
print(vPath);
// http://product.acirfa.tech:3000/products/224213463241
print(vUri);
var response = await http.get(vUri);
print(response);
if (response.statusCode == 200) {
print('OK');
} else {
print('KO');
}}
I have printed out the URI (vUri) that I passed as argument to the http.get() method and by clicking on it, I get the data via browser. The print out of the variable "response" is not executed, which makes me think the issue comes from vUri. Although, I have tried to create the URI with the URI Http constructor[Uri.http()], I saw the same behaviour.
Expected Result
I expected to see the print out OK
Any thoughts on where i am going wrong ? Thanks :)