gpt4 book ai didi

json - 抛出另一个异常 : HttpException: Connection closed while receiving data, uri =

转载 作者:IT王子 更新时间:2023-10-29 06:58:49 25 4
gpt4 key购买 nike

我正在尝试从 JSON API 获取图像,我在开放数据 JSON 中创建了 2 个链接,链接为:http://www.json-generator.com/api/json/get/bOEcLwbyqa?indent=2

错误:抛出另一个异常:HttpException:连接在接收数据时关闭,uri =

“picturep”有效(第一个截图),但“picture”无效(第二个截图),

我正在使用带有网络图像的 CicleAvatar:

leading:CircleAvatar(
backgroundImage: NetworkImage(user.picturep),
),

类(class):

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class MyInherited extends StatefulWidget {
final Widget child;

MyInherited({this.child});

@override
MyInheritedState createState() => new MyInheritedState();

static MyInheritedState of(BuildContext context) {
return (context.inheritFromWidgetOfExactType(_MyInherited) as _MyInherited).data;
}
}

class MyInheritedState extends State<MyInherited> {
String _myField;

List<String> names;
// only expose a getter to prevent bad usage
String get myField => _myField;

void onMyFieldChange(String newValue) {
setState(() {
_myField = newValue;
});
}

Future<UsersList> fetchUser() async {

final response = await http.get('http://www.json-generator.com/api/json/get/bOEcLwbyqa?indent=2');

if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return UsersList.fromJson(json.decode(response.body));
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}

@override
Widget build(BuildContext context) {
return new _MyInherited(
data: this,
child: widget.child,
);
}
}

/// Only has MyInheritedState as field.
class _MyInherited extends InheritedWidget {
final MyInheritedState data;

_MyInherited({Key key, this.data, Widget child}) : super(key: key, child: child);

@override
bool updateShouldNotify(_MyInherited old) {
return true;
}
}

class UsersList {
final List<User> users;

UsersList({ this.users, });

factory UsersList.fromJson(List<dynamic> parsedJson) {
List<User> photos = new List<User>();
photos = parsedJson.map((i) => User.fromJson(i)).toList();

return new UsersList(users: photos);
}
}

class User {
String sId;
String name;
String email;
String picture;
String picturep;
String address;
int age;
String gender;

User(
{this.sId,
this.name,
this.email,
this.picture,
this.picturep,
this.address,
this.age,
this.gender});

User.fromJson(Map<String, dynamic> json) {
sId = json['_id'];
name = json['name'];
email = json['email'];
picture = json['picture'];
picturep = json['picturep'];
address = json['address'];
age = json['age'];
gender = json['gender'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['_id'] = this.sId;
data['name'] = this.name;
data['email'] = this.email;
data['picture'] = this.picture;
data['picturep'] = this.picturep;
data['address'] = this.address;
data['age'] = this.age;
data['gender'] = this.gender;
return data;
}
}

我在努力

enter image description here enter image description here

最佳答案

这是新的 Android Studio 更新的新问题。默认情况下启用 Android Studio HTTP 代理,如果代理认为连接不安全(尤其是 HTTP 连接而非 HTTPS 连接),这似乎会导致连接因安全原因而中断。您有 2 个选项,使用 HTTPS 连接并确保连接绝对安全,或者在您的 android 模拟器中禁用 android studio 代理配置。

方案二如下:

go to emulator settings

enter image description here

关于json - 抛出另一个异常 : HttpException: Connection closed while receiving data, uri =,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54349683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com