C# 基础连接已关闭:远程服务器上的发送发生意外错误
当我尝试使用https方向调用远程站点上的REST服务时,会出现以下错误: 基础连接已关闭:发送时发生意外错误 这是我的密码:C# 基础连接已关闭:远程服务器上的发送发生意外错误,c#,json,rest,ssl,https,C#,Json,Rest,Ssl,Https,当我尝试使用https方向调用远程站点上的REST服务时,会出现以下错误: 基础连接已关闭:发送时发生意外错误 这是我的密码: public MyWebRequest(string url, string method, string data) { Uri uri = new Uri(url); HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest; req
public MyWebRequest(string url, string method, string data)
{
Uri uri = new Uri(url);
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
request.ContentType = "application/json";
request.Method = method;
request.ContentLength = data.Length;
string base64Credentials = GetEncodedCredentials(); // check below
request.Headers.Add("Authorization", "Basic " + base64Credentials);
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true; // **** Always accept
};
// -------------> The next line makes the error <------------------
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(data);
}
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
string result = string.Empty;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
}
Console.Write("Resultado: "+result);
}
这与VBA有什么关系?或者C#?我需要C#中的,但是如果你有VBA中的解决方案,欢迎。。
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
};