Я боролся около дня, пытаясь аутентифицироваться в 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;
}
}
Спасибо!