Flutter App failed to make HTTP request on iOS simulator Flutter App failed to make HTTP request on iOS simulator dart dart

Flutter App failed to make HTTP request on iOS simulator


If none of the API's are working in simulator, I assume this is due to your systems proxy settings since it uses your machines internet. Please have a look.


I was able to get it working with Dio using the below code in iOS simulator, if you want to see how http work check the cookbook, also try connecting to an open network like home wifi or something and see...

Note: This is a piece from iOS/ Android flutter project

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();          })        ),      ),    );  }}

RESPONSE

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"<…>