【声明:】本文是作者(蘑菇v5)原创,版权归作者 蘑菇v5所有,侵权必究。本文首发在简书。如若转发,请注明作者和来源地址!未经授权,严禁私自转载!
step1:
需要导入http
包,import 'package:http/http.dart'as http;
step2:
发起一个http
的get
请求,并将返回结果打印在控制台里
//指定url并发起请求
const url='http://httpbin.org';
http.get(url).then((response){
print("状态:${response.statusCode}");
print("正文:${response.body}");
});
step3:
程序请求地址时,服务器正常返回数据,则状态码为200
。
控制台返回结果如下:

网友评论