首页 > 解决方案 > 无法使用 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

标签: androidandroid-studiopostdartflutter

解决方案


推荐阅读