gpt4 book ai didi

c# - SSL 证书问题 - 根据验证程序,远程证书无效

转载 作者:行者123 更新时间:2023-11-30 13:37:50 27 4
gpt4 key购买 nike

尝试通过 C# 桌面应用程序将文件上传到我的服务器时出现以下错误:“根据验证程序,远程证书无效。”这与SSL证书有关。这是我的网站,由 Arvixe 托管。这是我使用的代码:

        public void Upload(string strFileToUpload)
{
FileInfo fiToUpload = new FileInfo(strFileToUpload);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.sd.arvixe.com/" + strDomain + "/wwwroot/OnlineGalleries/" + strOnlineGalleryName + "/Gallery/" + fiToUpload.Name);
request.EnableSsl = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("usr", "psw");
Stream sFTP = request.GetRequestStream();
FileStream file = File.OpenRead(strFileToUpload);
int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;
do
{
bytesRead = file.Read(buffer, 0, length);
sFTP.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
file.Close();
sFTP.Close();
}

如果我设置 request.EnableSsl = false,此代码可以正常工作。我不知道该怎么办。我已尝试将 URI 设置为 ftps://和 sftp://,但它们返回错误“无法识别 URI 前缀”。任何帮助表示赞赏。

最佳答案

很难测试您的代码,因为它连接到公共(public)服务。但是,如果您只想忽略 SSL 错误,也许这可以帮助您做到这一点:

System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

关于c# - SSL 证书问题 - 根据验证程序,远程证书无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20510316/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com