상속: System.Net.Browser.HttpWebResponseCore
예제 #1
0
        public override WebResponse EndGetResponse(IAsyncResult asyncResult)
        {
            try {
                if (async_result != asyncResult)
                {
                    throw new ArgumentException("asyncResult");
                }

                if (aborted)
                {
                    NativeMethods.http_request_abort(native);
                    throw new WebException("Aborted", WebExceptionStatus.RequestCanceled);
                }

                if (!async_result.IsCompleted)
                {
                    async_result.AsyncWaitHandle.WaitOne();
                }

                if (async_result.HasException)
                {
                    throw async_result.Exception;
                }

                response = async_result.Response as BrowserHttpWebResponse;
            }
            finally {
                async_result.Dispose();
                managed.Free();
            }

            return(response);
        }
예제 #2
0
        void OnAsyncDataAvailable(IntPtr sender, IntPtr calldata, IntPtr closure)
        {
            IntPtr data   = IntPtr.Zero;
            uint   length = 0;
            BrowserHttpWebResponse response = async_result.Response as BrowserHttpWebResponse;

            try {
                data        = NativeMethods.http_request_write_event_args_get_data(calldata);
                length      = NativeMethods.http_request_write_event_args_get_count(calldata);
                bytes_read += length;
                if (progress != null)
                {
                    // if Content-Encoding is gzip (or other compressed) then Content-Length cannot be trusted,
                    // if present, since it does not (generally) correspond to the uncompressed length
                    long content_length         = response.ContentLength;
                    bool compressed             = (response.IsCompressed || (content_length == 0));
                    long total_bytes_to_receive = compressed ? -1 : content_length;
                    progress(bytes_read, total_bytes_to_receive);
                }
            } catch (Exception e) {
                async_result.Exception = e;
            }

            try {
                if (data != IntPtr.Zero && length != 0)
                {
                    response.Write(data, checked ((int)length));
                }
            } catch (Exception e) {
                async_result.Exception = e;
            }
        }
예제 #3
0
        private void FlashPolicyCallback(IAsyncResult result)
        {
            WebRequest             wreq = (result.AsyncState as WebRequest);
            BrowserHttpWebResponse wres = (BrowserHttpWebResponse)wreq.EndGetResponse(result);

            // we either got a Flash policy or (if none/bad) a NoAccessPolicy, either way we continue...
            policy = CrossDomainPolicyManager.BuildFlashPolicy(wres);
            GetResponse(this.Method, uri, true);
        }
예제 #4
0
 static void OnHttpHeader(IntPtr context, IntPtr name, IntPtr value)
 {
     try {
         BrowserHttpWebResponse response = (BrowserHttpWebResponse)GCHandle.FromIntPtr(context).Target;
         response.InternalHeaders [Marshal.PtrToStringAnsi(name)] = Marshal.PtrToStringAnsi(value);
     } catch {
         // dont leak exceptions to native code
     }
 }
예제 #5
0
 void OnAsyncResponseStopped(IntPtr sender, IntPtr calldata, IntPtr closure)
 {
     try {
         if (progress != null)
         {
             BrowserHttpWebResponse response = async_result.Response as BrowserHttpWebResponse;
             // report the 100% progress on compressed (or without Content-Length)
             if (response.IsCompressed)
             {
                 long length = response.ContentLength;
                 progress(length, length);
             }
         }
     }
     finally {
         async_result.SetComplete();
     }
 }
예제 #6
0
        private void SilverlightPolicyCallback(IAsyncResult result)
        {
            WebRequest             wreq = (result.AsyncState as WebRequest);
            BrowserHttpWebResponse wres = (BrowserHttpWebResponse)wreq.EndGetResponse(result);

            policy = CrossDomainPolicyManager.BuildSilverlightPolicy(wres);
            if (policy != null)
            {
                // we got our policy so we can proceed with the main request
                GetResponse(this.Method, uri, true);
            }
            else
            {
                // no policy but we get a second chance to try a Flash policy
                Uri flash_policy_uri = CrossDomainPolicyManager.GetFlashPolicyUri(wres.ResponseUri);
                BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal(null, flash_policy_uri);
                preq.BeginGetResponse(new AsyncCallback(FlashPolicyCallback), preq);
            }
        }
예제 #7
0
		public override WebResponse EndGetResponse (IAsyncResult asyncResult)
		{
			try {
				if (async_result != asyncResult)
					throw new ArgumentException ("asyncResult");

				if (aborted) {
					NativeMethods.http_request_abort (native);
					throw new WebException ("Aborted", WebExceptionStatus.RequestCanceled);
				}

				if (!async_result.IsCompleted)
					async_result.AsyncWaitHandle.WaitOne ();

				if (async_result.HasException) {
					throw async_result.Exception;
				}

				response = async_result.Response as BrowserHttpWebResponse;
			}
			finally {
				async_result.Dispose ();
				managed.Free ();
			}

			return response;
		}