Flutter:发布带有凭证的请求 [英] Flutter : Post request with credentials
本文介绍了Flutter:发布带有凭证的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从flutter发出发帖请求。我需要使用用户的电子邮件地址和密码对用户进行身份验证。请帮助
How can I make post requests from flutter.I need to authenticate a user with his email address and password. Please help
尝试以下代码
http.post(url, body: {"email": "email", "password": "password"})
.then((response) {
print("Response status: ${response.statusCode}");
//print("Response body: ${response.body}");
});
收到防火墙读取失败或超时错误
getting "firewall read failed or timeout" error
推荐答案
我使用
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(...)
这篇关于Flutter:发布带有凭证的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文