c# – 连接到MailChimp v3.0 API

我有一个问题,连接到新的MailChimp 3.0 API(2.0工作正常).

我想发送一些订阅者.我究竟做错了什么?我可能正在尝试以错误的方式发送apikey(HTTP基本身份验证).文档在这里,但我无法使其工作:http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://us12.api.mailchimp.com/3.0/lists/<listnumber>/members/");

string json = @"
    {
        ""email_address"": ""test@test.com"",
        ""status"": ""subscribed"",
        ""merge_fields"": {
                    ""FNAME"": ""Urist"",
            ""LNAME"": ""McVankab""
        }
    }
";

byte[] data = Encoding.UTF8.GetBytes(json);

request.Method = "POST";
request.Headers.Add("user", "<mykeynumber>");
request.ContentType = "application/json";
request.ContentLength = data.Length;

using (System.IO.Stream stream = request.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

最佳答案 主要问题似乎是身份验证.这是一个很好的答案, demonstrates HTTP Basic Auth with
HTTPWebRequest.

点赞