从本地主机检索数据时,连接在接收数据(通过 NetworkImage 的图像)时关闭

Pur*_*kta 6 flutter flutter-test flutter-dependencies flutter-layout flutter-image

从网络本地主机检索图像文件时,http://10.0.2.2:8000出现以下错误:
\nConnection closed while receiving data.

\n

当我从 URL 调用数据(仅限图像)时出现错误。
\n请注意,我使用的是本地服务器。
\nI\xe2\x80\x99m 试图将图像放入其中Image.network(),这是图像代码。

\n
Image.network(urllink)\n
Run Code Online (Sandbox Code Playgroud)\n

相同的 URL 在本地主机浏览器和邮递员中也可以正常工作。
\n我正在尝试检索装饰框小部件中的图像。
\n当我在网络图像函数中粘贴直接 url 时,相同的 url 和图像可以工作,但当我尝试通过 api 获取照片名时发生错误。\n我得到的照片名和 API 工作正常。没有任何问题。

\n
 child: FutureBuilder<MatrimonyProfileData>(\n                  future: futureMData,\n                  builder: (context, snapshot) {\n                    if (snapshot.hasData) {\n                      // String matrimonyUrl = \'/$matrimonyprofileUrl\';\n                      String photoName = snapshot.data!.matrimonies.photo;\n\n                      print(photoName);\n                      //var fullUrl = _url + apiUrl\n\n                      var url;\n                      // urllink = \'http://10.0.2.2:8000/matrimony/profile.jpg\';\n\n                      **url = (webLink + matrimony + photoName);\n                      print(url);\n                      String urllink = Url;**\n                      return Column(\n                        children: [\n                          Container(\n                            color: Colors.deepPurpleAccent.shade100,\n                            child: Column(\n                              children: <Widget>[\n                                Container(\n                                  margin: const EdgeInsets.all(15.0),\n                                  padding: const EdgeInsets.all(3.0),\n                                  decoration: BoxDecoration(\n                                      border: Border.all(\n                                          color: Colors.black, width: 3)),\n                                  child: Wrap(\n                                    // mainAxisAlignment: MainAxisAlignment.end,\n                                    // direction: Axis.vertical,\n                                    children: <Widget>[\n                                      \n                                Container(\n                                  height: 300,\n                                  width: 400,\n                                  //color: Colors.amber,\n                                  child: Row(\n                                    children: <Widget>[\n                                      Container(\n                                          height: 300,\n                                          width: 170,\n                                          //color: Colors.amber,\n                                          decoration: BoxDecoration(\n                                            image: DecorationImage(\n                                                image: **NetworkImage(urllink),**\n\n                                                \n                                                fit: BoxFit.fitWidth),\n                                            \n                                          )),\n                                      // SizedBox(\n                                      //   width: 20,\n                                      // ),\n
Run Code Online (Sandbox Code Playgroud)\n

此链接上也存在同样的问题\nhttps://askandroidquestions.com/2021/07/12/flutter-exception-connection-closed-while-receiving-data/

\n

小智 2

Keep-Alive您的 http 请求中可能缺少标头。

尝试将其添加到您的请求标头中:

  "Connection": "Keep-Alive",
Run Code Online (Sandbox Code Playgroud)