login method
Before using the other api, you need login firstly. This method will fetch cookies and save them to the instance of K3Client. When you use the other api, the cookies will send automaticallly.
param
For building the parameters to request the interface of login.
At last, the response will be returned as the json Map format.
Implementation
Future<LoginInfo> login(LoginParam param) async {
if (_domain == null) throw Exception("domain msut be not null");
_cookies.clear();
String url = _domain! + _prefix + param.getRequestPath() + _suffix;
var resp = await _postJson(url, jsonEncode(param.toJson()));
if (resp.statusCode != HttpStatus.ok) throw Exception("http error, http status code is ${resp.statusCode}.");
// 获取cookie
_cookies = resp.cookies;
String body = await resp.transform(utf8.decoder).join();
LoginInfo info = LoginInfo.fromJson(param.parseResponse(body));
loginInfo = info;
return info;
}