0

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 Answer 1

1

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 :))

Sign up to request clarification or add additional context in comments.

1 Comment

the back-end thing worked but isn't there something I can do to get any site like google.com without using a third site?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.