我正在尝试使用颤振登录 API。这是方法:
var result = await http.post(
Uri.https(host, url, queries),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'username': myUsername,
'password': myPassword,
}),
);
带有 405 错误的请求结果说:
This method requires HTTP POST
请问,我该如何处理?
编辑:
这似乎有效:
Map<String, String> formMap = {
'username': 'myUsername',
'password': 'myPassword',
};
http.Response response = await http.post(
Uri.https(host, url, queries),
body: jsonEncode(formMap),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
encoding: Encoding.getByName("utf-8"),
);
- 状态码 200
- 响应正文 = {"stat":"fail","err":1002,"message":"缺少参数:用户名"}
看起来服务器无法识别我的请求的“正文”。