0
votes

I'm trying to do a get request using HTTP just to get google and display it as text.

My code works in both Android and iOS but not in web.

String _google;

void _onClick() async {
  final _res = await http.get('https://www.google.com');
  print(_res.body);
  setState(() => _google = _res.body);
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text(''),
    ),
    body: Center(
      child: Text(_google ?? 'null'),
    ),
    floatingActionButton: FloatingActionButton(
      onPressed: _onClick,
      child: Icon(Icons.send),
    ),
  );
}
1

1 Answers

1
votes

I don't know what has caused this issue to happen but a good workaround is to use the website cors-anywhere.herokuapp.com as a proxy; or add res.header('Access-Control-Allow-Origin', '*') to your back-end responses.

I'm sure it helps :))