ASP.NET C# Web サイトで Mail Chimp の新しい API を実装しようとしているので、ユーザーがメール アドレスを入力ボックスに入力すると、mailchimp リストに自動的に追加されます。他のさまざまな方法を試しましたが、どれもうまくいきませんでした。
405 Cannot use that Method 応答をスローした Web クライアントと、タスクではないためスター付きの GetStringAsync メソッド呼び出しでエラーをスローした HttpClient を試しました。
これまでの私のコードは以下のとおりです。
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;
//}
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", _apiKey);
string content = await http.**GetStringAsync**(@"https://us11.api.mailchimp.com/3.0/lists");
Console.WriteLine(content);
}
}
return false;
}