我尝试发送POST请求以将订阅者添加到列表中,以使用他们的3.0 API发送黑猩猩。我发送请求,但我得到的错误是405 - 方法不允许错误,我不明白如何解决。
我正在使用Http客户端发送PostAsync请求。
非常感谢任何帮助。
代码:
JavaScriptSerializer jss = new JavaScriptSerializer();
HttpClient client = new HttpClient();
foreach (MailChimpSubscriberModel subscriber in newSubscribers)
{
Subscriber member = new Subscriber();
member.email = subscriber.Email;
member.subscribed = "subscribed";
var url = "https://" + _dataPoint + ".api.mailchimp.com/3.0/lists/" + _defaultListId + "/";
string jsonString = jss.Serialize(member);
StringContent stringContent = new StringContent(jsonString);
stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _apiKey);
HttpResponseMessage response = await client.PostAsync(url, stringContent);
Trace.WriteLine("Response StatusCode: " + (int)response.StatusCode);
}
答案 0 :(得分:1)
在http://kb.mailchimp.com/api/resources/lists/lists-instance
查看MailChip API它看起来不像/ lists / {list_id}接受您使用PostAsync()进行的POST请求。