【发布时间】:2017-09-25 05:31:47
【问题描述】:
我正在使用以下代码从我的 WCF Web 服务发送推送通知
using (var wc = new WebClient())
{
wc.Headers.Add("Authorization", "Key=" + ConfigurationSettings.AppSettings["apiKey"]);
var nameValues = new NameValueCollection
{
{"registration_id", objSendNotificationBE.RegistrationID},
{"collapse_key", Guid.NewGuid().ToString()},
{"data.payload", objSendNotificationBE.Message}
};
var resp = wc.UploadValues("https://android.googleapis.com/gcm/send", nameValues);
respMessage = Encoding.Default.GetString(resp);
if (respMessage == "Error=InvalidRegistration")
{
string respMessage = "";
}
}
它工作正常,但有时我会遇到异常
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data)
at System.Net.WebClient.UploadValues(String address, NameValueCollection data)
我已经在 azure 服务器上部署了我的 Web 服务。
【问题讨论】:
-
你能正确格式化你的代码吗?目前很难阅读
-
尝试添加ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;使用前 (var wc = new WebClient())
-
尊敬的 Jitenderthanx 的回复,但正如我提到的,这个问题有时会不定期出现,我如何检查为什么它只发生在某个时间而不是针对所有请求。