【发布时间】:2021-06-27 19:35:02
【问题描述】:
所以,我正在尝试在 dart 中创建登录/注册表单:
// SERVER LOGIN API URL
var url = 'https://www.mywebsite.com/apicall.php';
// Store all data with Param Name.
var data = {'email': email, 'password': password};
// Starting Web API Call.
var response = await http.post(url, body: json.encode(data));
但我得到这个错误:
Error: The argument type 'String' can't be assigned to the parameter type 'Uri'.
- 'Uri' is from 'dart:core'.
var response = await http.post(url, body: json.encode(data));
有什么办法解决吗?
【问题讨论】:
-
正确方式:
var response = await http.post(Uri.parse(url), body: json.encode(data)); -
问:有什么办法可以解决这个问题?答:是的。例如
var url = Uri.parse(''https://www.mywebsite.com/apicall.php'); http.post() 需要一个 Uri 对象。 “字符串”是一种 DIFFERENT 类型的对象。 Uri.parse() 是从“字符串”初始化“Uri”的一种方法。 -
这能回答你的问题吗? The argument type 'String' can't be assigned to the parameter type 'Uri' BTW,很容易搜索关于特定错误消息的现有问题。