我目前正在尝试使用Dart编程语言使用摘要式身份验证发出http POST请求。唯一支持http摘要身份验证的Dart http类是dart:io:HttpClient类。
setup() async {
var httpclient = new HttpClient();
httpclient.addCredentials(Uri.parse("https://example.com/pearson-rest/services/PublicPortalServiceJSON"), "Protected", new HttpClientDigestCredentials("pearson", "m0bApP5"));
await httpclient.postUrl(Uri.parse("https://example.com/pearson-rest/services/PublicPortalServiceJSON"))
.then((HttpClientRequest request) {
request.headers.set("Content-Type", "text/xml; charset=utf-8");
request.headers.set("SOAPAction", "https://example.com:443/pearson-rest/services/PublicPortalServiceJSON#loginToPublicPortal");
request.headers.set("Host", "example.com:443");
request.headers.set("User-Agent", "Apache-HttpClient/UNAVAILABLE (java 1.5)");
request.write("""<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns="http://publicportal.rest.powerschool.pearson.com/xsd"><soap:Body><login xmlns="http://publicportal.rest.powerschool.pearson.com/xsd"><username><![CDATA["""+ studentUsername +"""]]></username><password><![CDATA["""+ studentPassword +"""]]></password><userType>2</userType></login></soap:Body></soap:Envelope>""");
return request.close();
})
.then((HttpClientResponse response) async {
print(response.statusCode);
print(response.headers);
print(await response.transform(UTF8.decoder).join());
});
}
请求对象似乎没有正文字段。文档也很糟糕,所以到目前为止我还无法找到解决方案。我认为write()方法相当于一个体,但事实并非如此。如何在HttpClient POST请求中添加正文?或者是否有一个不同的类支持摘要身份验证?