C# Salesforce marketing云API不返回访问/授权令牌
我有一个应用程序,它向营销云请求访问令牌,以便在随后的访问API的请求中使用。这是去年设计的,一直到上周都运转良好。自2002年2月22日以来,相同的请求一直失败。以下是请求令牌的示例代码:C# Salesforce marketing云API不返回访问/授权令牌,c#,https,dotnet-httpclient,exacttarget,salesforce-marketing-cloud,C#,Https,Dotnet Httpclient,Exacttarget,Salesforce Marketing Cloud,我有一个应用程序,它向营销云请求访问令牌,以便在随后的访问API的请求中使用。这是去年设计的,一直到上周都运转良好。自2002年2月22日以来,相同的请求一直失败。以下是请求令牌的示例代码: public static async Task<string> GetAuthorizationToken(string ClientId, string ClientSecret) { string strAuthorizationToken = string.Emp
public static async Task<string> GetAuthorizationToken(string ClientId, string ClientSecret)
{
string strAuthorizationToken = string.Empty;
HttpClient client = new HttpClient();
var dictParams = new Dictionary<string, string>()
{
{ "clientId", ClientId }, {"clientSecret", ClientSecret }
};
var content = new FormUrlEncodedContent(dictParams);
var response = await client.PostAsync("https://auth.exacttargetapis.com/v1/requestToken", content);
if (response.IsSuccessStatusCode)
{
var strresponse = await response.Content.ReadAsStringAsync();
//dynamic objResult = JsonConvert.DeserializeObject<dynamic>(strresponse);
//strAuthorizationToken = objResult.accessToken;
}
return strAuthorizationToken;
}
GetAuthorizationToken("*********", "*******").GetAwaiter().GetResult();
我需要知道这个代码中发生了什么变化,或者需要修复什么才能再次访问API。请帮助我如何使这项工作再次。
提前感谢。我正在发布答案,因为它已经解决,可能对其他在发送http请求时遇到类似问题的人有所帮助 我必须添加以下代码行来指定要使用的安全协议:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;
那么,自第一次实现以来,您的代码中没有任何变化?可能是因为他们不再支持你的应用程序正在使用的TLS版本,比如说他们需要TLS 1.2,而你的应用程序只支持TLS 1.0和1.1?查看salesforce API中的更改,查看他们正在更改其rest API。从一开始就没有任何代码更改。这是对营销云授权URL的简单web HTTP请求。当我将clientId和secret作为Json传递时,它在postman工具中工作。因此,我更新了代码以传递Json内容
var content=newstringcontent(strContent,Encoding.UTF8,“application/json”)代码>当我执行代码时,它仍然失败。我会非常确定地检查他们是否进行了恶意更新以要求TLS 1.2,并且您的应用程序不支持它,因为邮递员可能被配置为支持它。@Davidenglin感谢David。这很有帮助。
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;