I am using flutter http package for fetch a webpage. I want to send http request like desktop.How can I do that ?
My User-Agent : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
my code ;
  String text="mert";
  var isLoading = false;
 _fetchData() async {
final response =
    await http.get("http://trscript.net");
if (response.statusCode == 200) {
 var document = parse(response.body.toString());
 if(document.querySelector("body > div > div.sol.yaklas > div:nth-child(1) > article > div.yazi_bilgi")!=null){
    text = document.querySelector("body > div > div.sol.yaklas > div:nth-child(1) > article > div.yazi_bilgi").text;
 }
} else {
  throw Exception('Failed to load photos');
}
}
Based on http package latest version documentation you should extend http.BaseClient.
A code snipped directly copied from docs:
lass UserAgentClient extends http.BaseClient {
  final String userAgent;
  final http.Client _inner;
  UserAgentClient(this.userAgent, this._inner);
  Future<http.StreamedResponse> send(http.BaseRequest request) {
    request.headers['user-agent'] = userAgent;
    return _inner.send(request);
  }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With