【问题标题】:POST using HttpClient to add to a list MailChimp API 3.0POST 使用 HttpClient 添加到列表 MailChimp API 3.0
【发布时间】:2015-08-18 13:11:41
【问题描述】:

我正在尝试使用他们的 3.0 API 发送一个 POST 请求以将订阅者添加到邮件黑猩猩的列表中。我发送了请求,但我得到的错误是 405 - Method not allowed 错误,我不明白如何修复。

我正在使用 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);
        }

【问题讨论】:

    标签: c# json post http-post httpclient


    【解决方案1】:

    http://kb.mailchimp.com/api/resources/lists/lists-instance查看MailChip API

    它看起来不像 /lists/{list_id} 接受您使用 PostAsync() 执行的 POST 请求。

    【讨论】:

    猜你喜欢
    • 2016-02-08
    • 2016-08-04
    • 2016-12-01
    • 2018-02-11
    • 2020-08-09
    • 2016-11-18
    • 2015-12-19
    • 2015-08-09
    相关资源
    最近更新 更多