コード例 #1
0
 private void beginRequestOutput()
 {
     try {
         using (Stream requestStream = this.request.GetRequestStream()) {
             this.reportForwardProgress();
             this.requestBody.Position = 0L;
             byte[] numArray = new byte[32768];
             int    num      = 0;
             while (true)
             {
                 int num1 = this.requestBody.Read(numArray, 0, 32768);
                 int num2 = num1;
                 if (num1 <= 0)
                 {
                     break;
                 }
                 this.reportForwardProgress();
                 requestStream.Write(numArray, 0, num2);
                 requestStream.Flush();
                 num += num2;
                 pWebRequest.RequestUpdateHandler requestUpdateHandler = this.UploadProgress;
                 if (requestUpdateHandler != null)
                 {
                     requestUpdateHandler(this, (long)num, this.request.ContentLength);
                 }
                 else
                 {
                 }
             }
         }
         this.beginResponse();
     } catch (Exception exception) {
         this.Complete(exception);
     }
 }
コード例 #2
0
 private void perform()
 {
     this.Aborted = false;
     this.abortRequest();
     try {
         this.reportForwardProgress();
         pWebRequest.threadPool.QueueWorkItem(new WorkItemCallback(this.checkTimeoutLoop));
         this.request        = this.CreateWebRequest();
         this.ResponseStream = this.CreateOutputStream();
         foreach (KeyValuePair <string, string> header in this.Headers)
         {
             this.request.Headers.Add(header.Key, header.Value);
         }
         if (this.Parameters.Count + this.Files.Count > 0)
         {
             this.request.ContentType = "multipart/form-data; boundary=-----------------------------28947758029299";
             foreach (KeyValuePair <string, string> parameter in this.Parameters)
             {
                 this.requestBody.WriteLine("-------------------------------28947758029299");
                 this.requestBody.WriteLine(string.Concat("Content-Disposition: form-data; name=\"", parameter.Key, "\""));
                 this.requestBody.WriteLine(string.Empty);
                 this.requestBody.WriteLine(parameter.Value);
             }
             foreach (KeyValuePair <string, byte[]> file in this.Files)
             {
                 this.requestBody.WriteLine("-------------------------------28947758029299");
                 this.requestBody.WriteLine(string.Concat(new string[] { "Content-Disposition: form-data; name=\"", file.Key, "\"; filename=\"", file.Key, "\"" }));
                 this.requestBody.WriteLine("Content-Type: application/octet-stream");
                 this.requestBody.WriteLine(string.Empty);
                 this.requestBody.Write(file.Value, 0, (int)file.Value.Length);
                 this.requestBody.WriteLine(string.Empty);
             }
             this.requestBody.WriteLine("-------------------------------28947758029299--");
             this.requestBody.Flush();
         }
         if (this.requestBody.Length == 0)
         {
             this.beginResponse();
         }
         else
         {
             this.request.Method        = "POST";
             this.request.ContentLength = this.requestBody.Length;
             pWebRequest.RequestUpdateHandler requestUpdateHandler = this.UploadProgress;
             if (requestUpdateHandler != null)
             {
                 requestUpdateHandler(this, 0L, this.request.ContentLength);
             }
             else
             {
             }
             this.reportForwardProgress();
             this.beginRequestOutput();
         }
     } catch (Exception exception) {
         this.Complete(exception);
     }
 }
コード例 #3
0
 private void beginResponse()
 {
     try {
         this.response = this.request.GetResponse() as HttpWebResponse;
         pWebRequest.RequestStartedHandler requestStartedHandler = this.Started;
         if (requestStartedHandler != null)
         {
             requestStartedHandler(this);
         }
         else
         {
         }
         this.internalResponseStream = this.response.GetResponseStream();
         this.checkCertificate();
         this.buffer = new byte[32768];
         this.reportForwardProgress();
         while (true)
         {
             int num = this.internalResponseStream.Read(this.buffer, 0, 32768);
             this.reportForwardProgress();
             if (num <= 0)
             {
                 break;
             }
             this.ResponseStream.Write(this.buffer, 0, num);
             this.responseBytesRead += num;
             pWebRequest.RequestUpdateHandler requestUpdateHandler = this.DownloadProgress;
             if (requestUpdateHandler != null)
             {
                 requestUpdateHandler(this, (long)this.responseBytesRead, this.response.ContentLength);
             }
             else
             {
             }
         }
         this.ResponseStream.Seek(0L, SeekOrigin.Begin);
         this.Complete(null);
     } catch (Exception exception) {
         this.Complete(exception);
     }
 }