Xamarin Android FTP 启动时的身份验证问题
Xamarin Android FTP authentication problem on startup
我正在使用 Xamarin 使用 C# 语言开发 Android 应用程序。
在这个应用程序中,我需要一个在设备启动后启动的服务,并在 FTP 服务器中上传文件。
如果我使用按钮单击操作启动此服务一切正常,但如果我使用 BroadcastReceiver 并拦截 BOOT_COMPLETED 事件以启动 FTP 连接,我会收到此错误:
ex.Message: The authentication or decryption has failed.
ex.StackTrace: at System.Net.FtpWebRequest.EndGetRequestStream (System.IAsyncResult asyncResult)
at System.Net.FtpWebRequest.GetRequestStream ()
at TestProject.FTPUtility.upload (System.String userName, System.String password, System.String sourceFile, System.String targetFile)
我不明白为什么只有在服务启动时才会收到认证或解密错误。我也尝试仅在 ping 成功后才开始连接(等待设备互联网连接),但没有任何改变。
我用这行代码解决了问题:
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
我正在使用 Xamarin 使用 C# 语言开发 Android 应用程序。 在这个应用程序中,我需要一个在设备启动后启动的服务,并在 FTP 服务器中上传文件。 如果我使用按钮单击操作启动此服务一切正常,但如果我使用 BroadcastReceiver 并拦截 BOOT_COMPLETED 事件以启动 FTP 连接,我会收到此错误:
ex.Message: The authentication or decryption has failed.
ex.StackTrace: at System.Net.FtpWebRequest.EndGetRequestStream (System.IAsyncResult asyncResult)
at System.Net.FtpWebRequest.GetRequestStream ()
at TestProject.FTPUtility.upload (System.String userName, System.String password, System.String sourceFile, System.String targetFile)
我不明白为什么只有在服务启动时才会收到认证或解密错误。我也尝试仅在 ping 成功后才开始连接(等待设备互联网连接),但没有任何改变。
我用这行代码解决了问题:
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };