POST使用HttpClient向列表中添加MailChimp API 3.0
本文关键字:MailChimp API 添加 使用 HttpClient 列表 POST | 更新日期: 2023-09-27 18:08:34
我试图发送一个POST请求,将订阅者添加到使用他们的3.0 API的邮件chimp列表。我发送请求,但我得到的错误是一个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);
}
在http://kb.mailchimp.com/api/resources/lists/lists-instance查看MailChip API
它看起来不像/lists/{list_id}接受POST请求,而你正在使用PostAsync()。