我正在尝试使用 Xamarin 制作一个示例 Android 应用程序,以实现通过 Azure 通知中心接收通知。
该应用程序在 Android 4 上运行良好,但在 Android 2.2 上它给了我这个消息和异常。我认为错误是由于 Xamarin.NotificationHub 中的调用而出现的:
await client.UploadStringTaskAsync(serverUrl, "POST", registrationPayload);
其中 serverUrl 是 Azure 通知中心中的端点
消息是
12-05 23:44:25.727 I/mono-stdout(642):获取响应流时出错(写入:身份验证或解密失败。):SendFailure
例外:
System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a\n
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.RemoteValidation (Mono.Security.Protocol.Tls.ClientContext context, AlertDescription description) [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0 \n at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0 \n
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n --- End of inner exception stack trace ---\n
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n --- End of inner exception stack trace ---\n at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n
at System.Threading.Tasks.TaskFactory`1[System.IO.Stream].InnerInvoke (System.Threading.Tasks.TaskCompletionSource`1 tcs, System.Func`2 endMethod, IAsyncResult l) [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.IO.Stream].GetResult () [0x00000] in <filename unknown>:0 \n
at System.Net.WebClient+<UploadDataTaskAsyncCore>c__asyncA.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Byte[]].GetResult () [0x00000] in <filename unknown>:0 \n
at System.Net.WebClient+<UploadStringTaskAsync>c__asyncD.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.TaskAwaiter`1[System.String].GetResult () [0x00000] in <filename unknown>:0 \n
at ByteSmith.WindowsAzure.Messaging.NotificationHub+<CreateRegistration>d__33.MoveNext () [0x0012c] in e:\\Projects\\Xamarin\\TestNotificationHub2\\Client\\TestNotificationHub2\\Xamarin.NotificationHub-master\\source\\ByteSmith.WindowsAzure.Messaging\\NotificationHub.cs:415 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.TaskAwaiter`1[ByteSmith.WindowsAzure.Messaging.Registration].GetResult () [0x00000] in <filename unknown>:0 \n
at ByteSmith.WindowsAzure.Messaging.NotificationHub+<Register>d__23.MoveNext () [0x00151] in e:\\Projects\\Xamarin\\TestNotificationHub2\\Client\\TestNotificationHub2\\Xamarin.NotificationHub-master\\source\\ByteSmith.WindowsAzure.Messaging\\NotificationHub.cs:314 \n--- End of stack trace from previous location where exception was thrown ---\n
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n
at System.Runtime.CompilerServices.TaskAwaiter`1[ByteSmith.WindowsAzure.Messaging.Registration].GetResult () [0x00000] in <filename unknown>:0 \n
我相信单声道中的 https 证书可能存在问题,不确定也不知道如何解决。