我挣扎了大约一天试图对Pardot API进行身份验证。它不喜欢我试图发布消息体的方式。所以我想发布适合我的解决方案。如果您有任何提示或替代方案,我希望听到它们。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var url = "https://pi.pardot.com/api/login/version/3";
//(Edit) Shorter way to pass the parameters below
//var postData = new List<KeyValuePair<string, string>>
//{
// new KeyValuePair<string, string>("email", "<value>"),
// new KeyValuePair<string, string>("password", "<value>"),
// new KeyValuePair<string, string>("user_key", "<value>")
//};
var postData = new Dictionary<string, string>
{
{"email", "<value>"},
{"password", "<value>"},
{"user_key", "<value>"}
};
var httpContent = new FormUrlEncodedContent(postData);
using (var client = new HttpClient())
{
HttpResponseMessage response = client.PostAsync(url, httpContent).Result;
if (response.IsSuccessStatusCode)
{
string resultValue = response.Content.ReadAsStringAsync().Result;
}
}
谢谢!