Home>

If you connect an image to an address whose protocol is HTTPS, then everything works fine.

final String _path= 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg';

If you connect an image to an address whose protocol is HTTP, then everything NOTworks.

final String _path= 'http://fr38060s.bget.ru/_html/perform/img/car.jpg';

Earlier, this problem was solved like this. In the file, in the applicationAndroidManifest.xmltag, the attribute was added

android:usesCleartextTraffic="true"

Now everything is different if you follow the link

I created a xmlfolder in android/app/src/main/res

Created network-security-config.xmlfile in it

<?xml version="1.0" encoding="utf-8"?><network-security-config> <base-config cleartextTrafficPermitted="true" /></network-security-config>

In AndroidManifest.xmladded

android:networkSecurityConfig="@xml/network-security-config"

next, complete code

                              

main.dart

import 'package:flutter/material.dart';
void main()=> runApp(const MyApp());
class MyApp extends StatelessWidget {
 const MyApp({Key? key}) : super(key: key);
 @override
 Widget build(BuildContext context) {
  return MaterialApp(
   debugShowCheckedModeBanner: false,
   title: 'Name App',
   theme: ThemeData(
    primarySwatch: Colors.blue,
   ),
   home: Scaffold(
    appBar: AppBar(
     title: const Text('Name Page'),
    ),
    body: const SafeArea(
     child: MyHomePage(),
    ),
   ),
  );
 }
}
class MyHomePage extends StatefulWidget {
 const MyHomePage({Key? key}) : super(key: key);
 @override
 _MyHomePageState createState()=> _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
 //works because https
 //final String _path= 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg';
 //doesn't work because httpfinal String _path= 'http://fr38060s.bget.ru/_html/perform/img/car.jpg'; @override
 void initState() {
  super.initState();
 }
 @override
 void dispose() {
  superdispose();
 }
 @override
 Widget build(BuildContext context) {
  return Align(
   alignment: Alignment.center,
   child: Image.network(
    _path,
    fit: BoxFit.contain,
    width: 300.0
    height: 400.0
   ),
  );
 }
}

I have a similar application, everything works through network-security-config.xml

Style-72022-01-15 20:59:40

Dear Style-7! Try pasting my image path if possible.

Sergey2022-01-15 21:01:51
  • Answer # 1

    Android checks the configuration before sending the request and throws an error either immediately or when connecting to the server.
    Your request (judging by the inscription on the screen) was successful. But the server returned the code403.
    That is, the problem is on the server side -he does not like the request and he denied access to the file.
    A couple of tests showed that the problem is inUser agent-the server does not like the default one from android, replacing it with a string from the browser corrects the situation, but I have no idea how to replace it in your case -I don’t know flutter (but it’s probably possible to set request headers there).
    Maybe it's better to fix this on the server side, otherwise the site might have problems when viewed from a mobile phone.

  • Answer # 2

    Android checks the configuration before sending the request and throws an error either immediately or when connecting to the server.
    Your request (judging by the inscription on the screen) was successful. But the server returned the code403.
    That is, the problem is on the server side -he does not like the request and he denied access to the file.
    A couple of tests showed that the problem is inUser agent-the server does not like the default one from android, replacing it with a string from the browser corrects the situation, but I have no idea how to replace it in your case -I don’t know flutter (but it’s probably possible to set request headers there).
    Maybe it's better to fix this on the server side, otherwise the site might have problems when viewed from a mobile phone.

  • Answer # 3

    As far as I understand, now you need to list the domains that can be accessed via HTTP:

    network-security-config.xml

    &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;network-security-config&gt;  &lt;domain-config cleartextTrafficPermitted="true"&gt;    &lt;domain includeSubdomains="true"&gt;fr38060s.bget.ru&lt;/domain&gt;    &lt;domain includeSubdomains="true"&gt;www.blablabla.com&lt;/domain&gt;  &lt;/domain-config&gt;&lt;/network-security-config&gt;

    Dear Spatz! Thank you so much, BUT Alas, THE IMAGE WILL NOT LOAD.

    Sergey2022-01-15 20:23:39
  • Answer # 4

    As far as I understand, now you need to list the domains that can be accessed via HTTP:

    network-security-config.xml

    &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;network-security-config&gt;  &lt;domain-config cleartextTrafficPermitted="true"&gt;    &lt;domain includeSubdomains="true"&gt;fr38060s.bget.ru&lt;/domain&gt;    &lt;domain includeSubdomains="true"&gt;www.blablabla.com&lt;/domain&gt;  &lt;/domain-config&gt;&lt;/network-security-config&gt;

    Dear Spatz! Thank you so much, BUT Alas, THE IMAGE WILL NOT LOAD.

    Sergey2022-01-15 20:23:39