Flutter:Post 请求凭据

Flutter : Post request with credentials

如何从 flutter.I 发出 post 请求,需要使用用户的电子邮件地址和密码对用户进行身份验证。请帮助

尝试使用以下代码

 http.post(url, body: {"email": "email", "password": "password"})
      .then((response) {
    print("Response status: ${response.statusCode}");
    //print("Response body: ${response.body}");
  });

出现"firewall read failed or timeout"错误

我用

import 'dart:async' show Future;
import 'dart:io'
    show HttpClient, HttpClientBasicCredentials, HttpClientCredentials;

import 'package:http/http.dart' show BaseClient, IOClient;

typedef Future<bool> HttpAuthenticationCallback(
    Uri uri, String scheme, String realm);

HttpAuthenticationCallback _basicAuthenticationCallback(
        HttpClient client, HttpClientCredentials credentials) =>
    (Uri uri, String scheme, String realm) {
      client.addCredentials(uri, realm, credentials);
      return new Future.value(true);
    };

BaseClient createBasicAuthenticationIoHttpClient(
    String userName, String password) {
  final credentials = new HttpClientBasicCredentials(userName, password);

  final client = new HttpClient();
  client.authenticate = _basicAuthenticationCallback(client, credentials);
  return new IOClient(client);
}
final http =
    createBasicAuthenticationIoHttpClient(_config.userName, _config.password);

http.get(...)