Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基础连接已关闭:远程服务器上的发送发生意外错误_C#_Json_Rest_Ssl_Https - Fatal编程技术网

C# 基础连接已关闭:远程服务器上的发送发生意外错误

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

当我尝试使用https方向调用远程站点上的REST服务时,会出现以下错误:

基础连接已关闭:发送时发生意外错误

这是我的密码:

 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;
            };