我开始在android中开发Android Studio IDE,我测试了我的应用程序emulator并且工作正常,但当我尝试直接在我的设备中测试应用程序时无法识别它并且控制台显示下一条消息:
等待设备.找不到USB设备
通过 http.dart 在 flutter 上调用 post API 时,出现以下错误:
HttpException:在收到完整标头之前连接已关闭,uri = http://192.168.3.218:12225/resourcabc/subresourceXYZ
当邮递员给出正确的回复时为什么会这样?我之前也看到有人问过这个问题。另外,我正在物理设备上进行调试:三星
这是代码
Future<Map> post(
String path, {
String token,
dynamic body,
bool parseResponse: false,
isFormData: false,
isUseBaseURL: false,
isEncoded: false,
}) async {
Uri uri;
uri =
isUseBaseURL ? Uri.parse('${Paths.baseUrl}/$path') : Uri.parse('$path');
print(uri.toString());
print(body.toString());
var request =
await client.postUrl(uri).timeout(const Duration(seconds: 30));
if (token != null) {
request.headers.add(HttpHeaders.authorizationHeader, 'Bearer $token');
} else {
print('token is null');
request.headers.add("X-Consumer-Custom-ID", "96");
}
if (body != null) {
if (isFormData) {
request
..headers.contentType = …Run Code Online (Sandbox Code Playgroud) 我有一个颤振应用程序。我通过 HTTP 在那里拍摄图像并希望缓存它们,因为滚动时所有内容都会再次加载并需要时间。\n我该如何解决这个问题?如果你能给出一个例子,请。\n有必要不再下载它。那些已加载的产品最好已经在缓存中或者至少是图片中。我怎样才能做到这一点?
\n//method gets products\nFuture<List<Product>> getProducts(int id) async {\nvar response = await http.get(Uri.parse('...'));\nfinal products = jsonDecode(response.body).cast<Map<String, dynamic>>();\n\nList<Product> list = products.map<Product>((json) => Product.fromJson(json)).toList();\n\nreturn list;}\n// parse json\nfactory Product.fromJson(Map<String, dynamic> data) {\nreturn Product(\n id: data['id'] as int,\n title: data['name'] as String,\n description: data['description'] as String,\n imgUrl: data['images'][0]['src'] as String,\n price: num.tryParse(data['price'])\n);}\n//draw products\nWidget build(BuildContext context) {\nfinal product = Provider.of<Product>(context, listen: false);\n\nreturn Container(\n width: 150,\n padding: const EdgeInsets.all(10.0),\n margin: const EdgeInsets.all(5.0),\n decoration: BoxDecoration(\n borderRadius: BorderRadius.circular(15.0),\n color: Color(422),\n ),\n child: Column(\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n crossAxisAlignment: …Run Code Online (Sandbox Code Playgroud) 我在尝试使用我的 API 时遇到问题,在跟进这个问题后,我陷入了困境,我尝试了不同版本的不同模拟器,但问题仍然存在。
错误:
DioError [DioErrorType.other]: HttpException: Connection closed before full header was received, uri = http://10.0.2.2:7108/Users/authenticate
Run Code Online (Sandbox Code Playgroud)
扑医生
HTTP 邮递
class AuthenticateRemoteApi extends AuthenticateGateway {
final AuthenticateMapper _authenticateMapper = AuthenticateMapper();
@override
Future<SesionUser> login(Authenticate user) async {
var dio = Dio();
dio.options.headers['content-Type'] = 'application/json';
String url = 'http://10.0.2.2:7108/Users/authenticate';
try {
Response response = await dio.post(url, data: authenticateModelToJson(user));
return _authenticateMapper.fromMap(jsonDecode(response.data));
} catch (e) {
throw Exception(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)