gpt4 book ai didi

dart - flutter : Post request with credentials

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

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

尝试使用以下代码

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

出现“防火墙读取失败或超时”错误

最佳答案

我用

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(...)

关于dart - flutter : Post request with credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49398382/

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