我可以在 iOS 模拟器中使用以下代码让它工作Dio
,如果你想看看如何http
检查食谱,还可以尝试连接到开放网络,如家庭 wifi 或其他东西,然后看看......
注意:这是来自 iOS/Android 的 Flutter 项目
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
fetchData()async {
Dio dio = new Dio();
Response response=await dio.get('https://www.baidu.com');
print(response.data);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fetch Data Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('Fetch Data Example'),
),
body: Center(
child: new IconButton(icon:new Icon(Icons.all_inclusive) , onPressed: (){
fetchData();
})
),
),
);
}
}
回复
flutter: <!DOCTYPE html>
<!--STATUS OK-->
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta content="always" name="referrer">
<meta name="theme-color" content="#2932e1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" />
<link rel="icon" sizes="any" mask href="//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg">
<link rel="dns-prefetch" href="//s1.bdstatic.com"<…>