Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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
.net 请求被中止,请求被取消_.net_C# 4.0 - Fatal编程技术网

.net 请求被中止,请求被取消

.net 请求被中止,请求被取消,.net,c#-4.0,.net,C# 4.0,我在StreamUtil.Copy上遇到失败问题,错误为“请求被中止,请求被取消”。我已经尝试增加请求的超时属性,即使它失败。任何建议都会有帮助。我也尝试过在内存流中传递请求,但没有成功 string MIMEBoundary = "--MIMEBoundary633737556018130000"; Uri urlUri = new Uri(url); Logger.Debug("Preparing form post.

我在StreamUtil.Copy上遇到失败问题,错误为“请求被中止,请求被取消”。我已经尝试增加请求的超时属性,即使它失败。任何建议都会有帮助。我也尝试过在内存流中传递请求,但没有成功

 string MIMEBoundary = "--MIMEBoundary633737556018130000";
            Uri urlUri = new Uri(url);            
            Logger.Debug("Preparing form post...");

            using (MemoryStream body = new MemoryStream())
            {
                this.GetPostData(body, MIMEBoundary, paramList);                
                body.Position = 0;

                HttpWebRequest myWeb = (HttpWebRequest)WebRequest.Create(urlUri);
               //ServicePointManager.DefaultConnectionLimit = 100;
               ServicePointManager.MaxServicePointIdleTime = 10000;
                System.Net.ServicePointManager.Expect100Continue = false;
                myWeb.AllowAutoRedirect = true;
                myWeb.KeepAlive = false;
                if (ignoreCertErrors)
                    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

                if (cookieContainer.Count > 0) {
                    Logger.Debug("Cookie container got cookies, len: " + cookieContainer.Count);
                    myWeb.CookieContainer = cookieContainer;
                }

                if (proxyHost != null)
                {
                    Logger.Debug("Using proxyHost: " + proxyHost);
                    myWeb.Proxy = new WebProxy(proxyHost, proxyPort.Value);
                }

                // force no proxy for private addrs
                Uri uri = new Uri(url);
                if (uri.Host.StartsWith("10.") || uri.Host.StartsWith("1.1.sample ip"))
                    myWeb.Proxy = new WebProxy();

               // myWeb.Method = "PS";
                myWeb.Method = type;
               myWeb.AllowWriteStreamBuffering = true;
              //   myWeb.AllowWriteStreamBuffering = false;
                myWeb.ProtocolVersion = HttpVersion.Version10;
                myWeb.Timeout = timeoutMS;
                // myWeb.Timeout =-1;// System.Threading.Timeout.Infinite;
                if (credential != null)
                    myWeb.Credentials = credential;

                string auxContent = "multipart/form-data;";

                auxContent += "boundary=" + MIMEBoundary;
                myWeb.ContentType = auxContent;

                myWeb.Accept = "iso-8859-1";
                myWeb.ContentLength = body.Length;
               // myWeb.ContentLength =byteArray.Length;  
                Stream reqStream = myWeb.GetRequestStream();

                Parts.IO.StreamUtil.Copy(body, reqStream);

                //try
                //{
                //    body.Seek(0, SeekOrigin.Begin);
                //    body.CopyTo(myWeb.GetRequestStream());
                //}

                //catch (Exception exp)
                //{
                //    Logger.Error("Publishing to Appstudio failed.", exp);

                //}
              //    myWeb.GetRequestStream().CopyTo(body);

          //   body.Write(
              //using (var ms = new MemoryStream())
              //{
              //    // Copy the response stream to the memory stream.
              //    myWeb.GetRequestStream().CopyTo(ms);
              //    ms.Write(myWeb, 0, myWeb.Length);
              //}

                //myWeb.GetRequestStream().CopyTo();
               /* string json_value = jsonSerializer.Serialize(data); //Body data
                ServicePointManager.Expect100Continue = false;
                using (var streamWriter = new StreamWriter(myWeb.GetRequestStream()))
                {
                    streamWriter.Write(json_value);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                Stream responseStream = myWeb.GetResponse();
                StreamReader myStreamReader = new StreamReader(responseStream);
                responseData = myStreamReader.ReadToEnd();

                Parts.IO.StreamUtil.Copy(body, ms);*/

                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myWeb.GetResponse();
                return myHttpWebResponse;
堆栈跟踪如下所示

在System.Net.ConnectStream.InternalWrite(布尔异步、字节[]缓冲区、Int32偏移量、Int32大小、异步回调、对象状态) 在System.Net.ConnectStream.Write(字节[]缓冲区,Int32偏移量,Int32大小) 在C:\dev\Parts\DotnetParts\IO\StreamUitl.cs中的Parts.IO.StreamUtil.Copy(流输入,流输出)处