首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过Httpclient将JSON数据发布到Pardot API

如何通过Httpclient将JSON数据发布到Pardot API
EN

Stack Overflow用户
提问于 2020-02-03 20:24:00
回答 1查看 353关注 0票数 0

我正在尝试将JSON数据发布到Pardot。我已经使用来自here的信息来调用Pardot API,并且当前使用Pardot表单处理程序来发布数据。我想知道是否可以使用CREATE或UPSERT而不是使用表单处理程序通过Pardot API调用来获取数据。下面是我的代码

代码语言:javascript
复制
class SendingDataToPardot
    {
        public string Login()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            var url = "https://pi.pardot.com/api/login/version/3";
            string apiKey = null;


            var loginInfo = new Dictionary<string, string>
            {
                {"email", "xx"},
                {"password", "xxx"},
                {"user_key", "xxx"}
            };

            var httpContent = new FormUrlEncodedContent(loginInfo);

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = client.PostAsync(url, httpContent).Result;

                if (response.IsSuccessStatusCode)
                {
                    string resultValue = response.Content.ReadAsStringAsync().Result;
                    apiKey = XDocument.Parse(resultValue).Element("rsp").Element("api_key").Value;


                    return apiKey;

                }
                else
                {
                    return null;
                }


            }
        }

        public string POST()
        {
            string Api_Key = Login();
            var url = "form handler url";

            var contactFormData = new Dictionary<string, string>
            {
                {"email", "test@test.com"},
                {"FirstName", "xxx"},
                {"LastName", "xxxxx"},
                {"Comments", "this is a test"}

            };

            var data= new FormUrlEncodedContent(contactFormData);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Api_Key);
                HttpResponseMessage response = client.PostAsync(url, data).Result;
                string result = response.Content.ReadAsStringAsync().Result;
                return result;
            }

        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2020-03-10 11:17:43

对于Pardot公开的大多数API,您都需要使用它进行XML工作。

看起来您正在使用Java,所以您可能会幸运地使用公共库,即使只是为了理解通信模式(我们必须重写它才能达到我们的目的,但它确实是一个很好的蓝图)。

看一看https://github.com/Crim/pardot-java-client项目,看看它是否对您有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60039183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档