尝试通过SSL对远程服务器执行HttpWebRequest时,我收到以下错误(网址为https://sandbox.payfast.co.za):
"根据验证程序,远程证书无效"
证书似乎是有效的,我可以成功地向另一个网址发出网络请求.
有人可以告诉我.NET如何验证证书以及如何找出证书的确切问题.
试图绕过这个我添加:
ServicePointManager.ServerCertificateValidationCallback
= (obj, certificate, chain, errors) => true;
Run Code Online (Sandbox Code Playgroud)
但似乎这对中等信任不起作用.
任何帮助赞赏.
谢谢Ben
在我的项目中,我需要从桌面应用程序上传大型JSON数据。因此,我需要对其进行压缩。
我到处搜索,但没有找到解决问题的复杂方法。因此,我将几个摘要放在一起。请参阅下面的答案。希望对你有帮助。
我有一个客户端 - 服务器类型的应用程序,服务器运行HttpListener,客户端使用WebClient.UploadData将数据上传到服务器.代码工作得很好(大数据缓冲区为60K及以上),除了一个安装,当数据缓冲区大小超过16384时,UploadData超时.这是我在客户端的代码:
internal bool UploadData(byte[] buffer, String file, String folder)
{
try
{
String uri = "http://" + GlobalData.ServerIP + ":" + GlobalData.ServerHttpPort + "/upload:";
NameValueCollection headers = new NameValueCollection();
headers.Set("Content-Type", "application/octet-stream");
headers.Set("Y-Folder", folder);
headers.Set("Y-File", file);
using (WebClient wc = new WebClient())
{
wc.Credentials = new NetworkCredential(WebUserName, WebPassword);
wc.Headers.Add(headers);
wc.UploadData(new Uri(uri), buffer);
return true;
}
}
catch (Exception ex)
{
GlobalData.ODS("Exception in UploadFile " + ex.Message);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
在服务器上
ODS(TraceDetailLevel.Level4, "Process upload ");
HttpListenerResponse response = e.RequestContext.Response; …Run Code Online (Sandbox Code Playgroud)