4

I tried to make a simple HTTP get request using Dio in a Flutter App like this:

Dio dio = new Dio();
Response response = await dio.get('https://www.baidu.com');
print(response.data.toString());

It works perfect on a real iOS device, but time out on iOS simulators.

SocketException: OS Error: Operation timed out, errno = 60

I also tried other packets such as http, but still time out. Native apps running on the simulator doesn't have the same problem. What can I do to fix it?

Tanvir Nayem
  • 702
  • 10
  • 25
BeBeBerr
  • 41
  • 1
  • 3

2 Answers2

0

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.

RameshVel
  • 64,778
  • 30
  • 169
  • 213
0

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"<…>
anoop4real
  • 7,598
  • 4
  • 53
  • 56