android - 无法使用 Android Studio/Dart 发送发布请求?
问题描述
我正在尝试使用 Flutter 1.0、dart 2.1 和 Android Studio 3.2.1 向远程服务器发送 POST 请求,但由于某种原因远程服务器没有收到任何内容。我尝试在自己的服务器上使用,也尝试使用 firebase,但没有任何运气。有人可以帮我解决我的错误吗?这是我的代码:
void addProduct(String title, String description, double price,
String image) {
final Map<String, dynamic> productData = {
'title': title,
'description': description,
'image': 'url',
'price': price
};
http.post('https://fir-numbers.firebaseio.com/products.json', body: json.encode(productData));
final Product newProduct = Product(
title: title,
description: description,
price: price,
image: image,
userEmail: _authenticatedUser.email,
userId: _authenticatedUser.id);
_products.add(newProduct);
notifyListeners();
}
我也在顶部
import 'dart:convert';
import 'package:scoped_model/scoped_model.dart';
import 'package:http/http.dart' as http;
在我的 pubspec.yaml 我有
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
scoped_model: ^0.3.0
http: ^0.12.0
解决方案
推荐阅读
- awk - 为两个文本文件中的多行扩展 awk 脚本,而不是如果两个文件只有一条记录
- java - 可以使用代理卷曲容器内的外部服务,但不能从 java / spring boot 请求(超时503)
- c++ - 我的图纸有坐标/ glortho 问题
- sql-server - 使用批量插入从当前目录加载 .csv 文件:SQL Server
- minecraft - Minecraft 脚本“造成的损坏”条件不起作用
- postgresql - PostgreSQL - 根据其他表的值选择值
- c - 我如何访问 typedef 结构中的变量
- python - 如何通过 xarray 在 NetCDF4 中求和
- javascript - 如果 API 没有要求登录,我如何获取我的 API 密钥
- angular - 如何使用 PrimeNG 对多列进行排序