【发布时间】:2017-06-18 05:29:40
【问题描述】:
使用 RestSharp 查询 MailChimp 帐户中的帐户详细信息时,我收到“401:未授权”和“API 密钥丢失”,即使它显然不是!
我们使用相同的方法通过几种不同的方法创建我们的 RestClient,并且在所有请求中它都可以完美地工作。但是,当我们尝试请求帐户详细信息时,意味着 RestRequest URI 为空,我们会收到这个奇怪的错误和消息。
例子:
private static RestClient CreateApi3Client(string apikey)
{
var client = new RestClient("https://us2.api.mailchimp.com/3.0");
client.Authenticator = new HttpBasicAuthenticator(null, apiKey);
return client;
}
public void TestCases() {
var client = CreateApi3Client(_account.MailChimpApiKey);
var req1 = new RestRequest($"lists/{_account.MailChimpList}/webhooks", Method.GET);
var res1 = client.Execute(req1); // works perfectly
var req2 = new RestRequest($"automations/{account.MailChimpTriggerEmail}/emails", Method.GET);
var res2 = client.Execute(req2); // no problem
var req3 = new RestRequest(Method.GET);
var res3 = client.Execute(req3); // will give 401, api key missing
var req4 = new RestRequest(string.Empty, Method.GET);
var res4 = client.Execute(req4); // same here, 401
}
在 Postman 中尝试 api 调用时一切正常。 https://us2.api.mailchimp.com/3.0,带有基本身份验证的 GET 为我提供了所有帐户信息,并且在 c# 中进行调试时,一切看起来都相同。
我正在尝试决定是否将责任归咎于 RestSharp 或 MailChimp API 中的错误。有没有人遇到过类似的问题?
【问题讨论】:
标签: mailchimp restsharp mailchimp-api-v3.0