0

Connection code

till yesterday everything working properly but now it giving the error to connect the json data. ...........................................................................................................................................................................................

class ProductDataStacture with ChangeNotifier {
  List<Products> _products = [];
  List<Banners> _banners = [];
  List<Categories> _category = [];
  List<Random> _random = [];

  Future<bool> getProducts() async {
    String url = 'https://shymee.com';

    try {
      // http.Response response = await http.get(Uri.parse(url + "/home"),
      var response = await http.get(Uri.parse(url + "/home"), headers: {
        'Authorization': 'token a867c3c092e8b1195f398ed5ca52dda4e5ff5ed8'
      });
      var data = json.decode(response.body);
      print(data);
      List<Products> prod = [];
      List<Banners> bann = [];
      List<Categories> cate = [];
      List<Random> ran = [];
      data['products'].forEach((element) {
        Products product = Products.fromJson(element);
        prod.add(product);
        print("this is product ${product}");
      });
      data['banners'].forEach((element) {
        Banners banner = Banners.fromJson(element);
        bann.add(banner);
      });
      data['categories'].forEach((element) {
        Categories category = Categories.fromJson(element);
        cate.add(category);
      });
      data['random'].forEach((element) {
        Random random = Random.fromJson(element);
        ran.add(random);
      });
      _products = prod;
      _banners = bann;
      _category = cate;
      _random = ran;
      return true;
    } catch (e) {
      print("e getProducts");
      print(e);
      return false;
    }
  }

  List<Products> get productsList {
    return [..._products];
  }

  List<Banners> get bannersList {
    return [..._banners];
  }

  List<Categories> get categoryList {
    return [..._category];
  }

  List<Random> get randomList {
    return [..._random];
  }
}
  • Just open the page in a browser to see that: "This server could not prove that it is shymee.com; its security certificate is from 9369-4057.com. This may be caused by a misconfiguration or an attacker intercepting your connection." Clearly there *is* a mismatch. – Richard Heap Dec 29 '21 at 17:53

1 Answers1

0

Temporary you can solve this issue with below recommend

class MyHttpOverrides extends HttpOverrides{
  @override
  HttpClient createHttpClient(SecurityContext? context){
    return super.createHttpClient(context)
     ..badCertificateCallback = (X509Certificate cert, String host, int 
    port)=> true;
 }
}

enter link description here

But my suggestion is you use valid certificate in server side

Hossein Asadi
  • 768
  • 1
  • 6
  • 15
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31987252) – bartektartanus Jun 15 '22 at 09:41