出于某种原因,我无法通过Android应用访问API。我通过Mac终端使用了相同的凭据,并收到了成功的回复。
这是我正在使用的当前代码:
String url = "https://" + dc + ".api.mailchimp.com/3.0/";
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestProperty("Authorization", "basic " + Base64.encode("saroy:myapikey".getBytes(), Base64.NO_WRAP));
conn.connect();
我还尝试了另一种方法,但这会返回API Key Missing
响应:
Authenticator.setDefault (new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("saroy", "myapikey".toCharArray());
}
});