我正在尝试使用我的ASP.NET C#网站实现Mail Chimp的新API,因此当用户将其电子邮件地址输入到输入框时,它将自动添加到我的mailchimp列表中.我尝试了其他各种方法,但这些方法都没有奏效.
我尝试过一个Web客户端,它抛出405不能使用该方法响应和一个HttpClient,它在星号GetStringAsync方法调用上引发错误,因为它不是一个任务.
我的代码到目前为止详述如下:
public bool BatchSubscribe(IEnumerable<MailChimpSubscriberModel> newSubscribers)
{
if (string.IsNullOrEmpty(_defaultListId)) throw new ArgumentNullException(Res.Resource.MailChimpIntegrationNoListId);
if (string.IsNullOrEmpty(_apiKey)) throw new ArgumentNullException(Res.Resource.MailChimpIntegrationNoApiKey);
foreach (MailChimpSubscriberModel subscriber in newSubscribers)
{
string url = "https://" + _dataPoint + ".api.mailchimp.com/3.0/lists/" + _defaultListId + "/";
Subscriber member = new Subscriber();
member.email = subscriber.Email;
member.subscribed = "subscribed";
string jsonString = new JavaScriptSerializer().Serialize(member);
//using (WebClient client = new WebClient())
//{
// client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
// client.Headers[HttpRequestHeader.Authorization] = new AuthenticationHeaderValue("Basic", _apiKey).ToString();
// string HtmlResult = client.(url, jsonString);
// return true; …Run Code Online (Sandbox Code Playgroud)