我有一个 Rest API 成功运行,并且可以将 curl 发布为:
curl -X POST "{{baseURL}}/api/auth/login" -H "accept: application/json" -H "Content-Type: application/json-patch+json" -d "{ \"nick\": \"string"\", \"password\": \"string\"}"
Run Code Online (Sandbox Code Playgroud)
我的愿望是编写一个代码来完成上述命令的确切工作,我的意思是如何以正确的方式解码/编码东西。这是我到目前为止得到的:
Future<http.Response> postRequest (String nick, String password) async {
var url ='{{baseURL}}/api/auth/login';
var body = jsonEncode({ "nick": "$nick", "password": "$password"});
print("Body: " + body);
http.post(url,
headers: {"accept": "application/json","Content-Type": "application/json-
patch+json"},
body: body
).then((http.Response response) {
});
}
Run Code Online (Sandbox Code Playgroud)
谢谢!