参考https://next.api.aliyun.com/api-tools/sdk/Dysmsapi?version=2017-05-25&language=csharp-tea这里的C#demo在发短信时报以下错误
One or more errors occurred. (The SSL connection could not be established, see inner exception.)
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
代码如下:
SmsClient = CreateClient(AccessKeyId, AccessKeySecret);
var msg = new AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsRequest()
{
PhoneNumbers = quest.to,
SignName = SignName,
TemplateCode = TemplateCode,
TemplateParam = string.Format("{{\"msg\":\"{0}\"}}", quest.text),
};
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true; ///参考网上方法加了这个也不行
AlibabaCloud.SDK.Dysmsapi20170525.Models.SendSmsResponse res = SmsClient.SendSms(msg); //这里报错
....
public static Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// 您的 AccessKey ID
AccessKeyId = accessKeyId,
// 您的 AccessKey Secret
AccessKeySecret = accessKeySecret,
};
// 访问的域名
config.Endpoint = "dysmsapi.aliyuncs.com";
return new Client(config);
}
完整异常信息如下:
2022-09-23 16:49:14,541 - Aliyun_smsService SendSMS Error:One or more errors occurred. (The SSL connection could not be established, see inner exception.)
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
at System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
...
at AlibabaCloud.OpenApiClient.Client.DoRequest(Params params_, OpenApiRequest request, RuntimeOptions runtime)
at AlibabaCloud.OpenApiClient.Client.CallApi(Params params_, OpenApiRequest request, RuntimeOptions runtime)
at AlibabaCloud.SDK.Dysmsapi20170525.Client.SendSmsWithOptions(SendSmsRequest request, RuntimeOptions runtime)
at AlibabaCloud.SDK.Dysmsapi20170525.Client.SendSms(SendSmsRequest request)
解决发短信问题
下面两个在SendSms试了都不行。
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
ServicePointManager.ServerCertificateValidationCallback =
delegate (
object s,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
) {
return true;
};
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。