[英]I am having an error while trying to make a get request on flutter
String url = 'http://localhost:9000/user/john.doe@email.com';
Future<String> get makeRequest() async {
var response = await http
.get(Uri.encodeFull(url), headers: {"Accept": "application"});
print(response.body);
}
I get an error on makeRequests() that says "This function has a return type of 'Future', but doesn't end with a return statement."我在 makeRequests() 上收到一条错误消息,上面写着“这个 function 的返回类型为 'Future',但不以返回语句结尾。”
You must return a String in the function with the header Future< String >.您必须在 function 和 header Future<String> 中返回一个字符串。 You probably want to return response.body您可能想返回 response.body
You have to return data corresponding to the return type of the function.您必须返回与 function 的返回类型对应的数据。
String url = 'http://localhost:9000/user/john.doe@email.com';
Future<String> get makeRequest() async
{
var response = await http.get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
print(response.body);
return(response.body);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.