我的收获API,一个非常标准的Web服务API的工作,虽然我的飞镖HttpClient的请求不是我的卷曲请求工作得很好。 这是我(变相当然,敏感信息)卷曲的要求:
curl -H "Content-Type: application/json" \
-H "Accept: application/json" \
-u "address@domain.com:password" \
https://my_domain.harvestapp.com/account/who_am_i
UPDATE ---下面的代码现在工作:
HttpClient client = new HttpClient();
client.addCredentials(
Uri.parse('https://my_domain.harvestapp.com/account/who_am_i'),
'realm',
new HttpClientBasicCredentials('address@domain.com', 'password')
);
client.getUrl(Uri.parse('https://my_domain.harvestapp.com/account/who_am_i'))
.then((HttpClientRequest req) {
req.headers
..add(HttpHeaders.ACCEPT, 'application/json')
..add(HttpHeaders.CONTENT_TYPE, 'application/json');
return req.close();
})
.then((HttpClientResponse res) {
print(res);
client.close();
});
}
很显然,我希望做更多的不是简单地print
响应,但无论怎样, res
对象最终被null
,这意味着该请求是在某些方面失败。 做任何事情似乎歪曲或不妥? 我茫然现在。