private IAsyncResult GetResponse(string method, Uri uri, bool sendHeaders) { if ((uri.Scheme != "http") && (uri.Scheme != "https")) { async_result.Exception = new SecurityException("Bad scheme"); async_result.SetComplete(); return(async_result); } // this is a same site (site of origin, SOO) request; or // we either already know the policy (previously downloaded); or // we try to download the policy if (!IsDownloadingPolicy()) { policy = CrossDomainPolicyManager.GetCachedWebPolicy(uri); if (policy == null) { // we'll download the policy *then* proceed to the requested URI policy = CrossDomainPolicyManager.PolicyDownloadPolicy; Uri silverlight_policy_uri = CrossDomainPolicyManager.GetSilverlightPolicyUri(uri); BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal(null, silverlight_policy_uri); return(preq.BeginGetResponse(new AsyncCallback(SilverlightPolicyCallback), preq)); } } // Console.WriteLine ("{0} '{1}' using policy: {2}", method, uri, policy); HttpWebRequest wreq = GetHttpWebRequest(uri); wreq.Method = method; // store exception, to throw later, if we have no policy or are not allowed by the policy #if !ANDROID_HACK if ((policy == null) || !policy.IsAllowed(wreq)) { if ((policy == null) || (policy.Exception == null)) { async_result.Exception = new SecurityException(); } else { async_result.Exception = policy.Exception; } async_result.SetComplete(); return(async_result); } #endif if (!sendHeaders) { wreq.Headers.Clear(); } wreq.progress = progress; return(wreq.BeginGetResponse(new AsyncCallback(EndCallback), wreq)); }
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); } }
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); } }
private IAsyncResult GetResponse (string method, Uri uri, bool sendHeaders) { if ((uri.Scheme != "http") && (uri.Scheme != "https")) { async_result.Exception = new SecurityException ("Bad scheme"); async_result.SetComplete (); return async_result; } // this is a same site (site of origin, SOO) request; or // we either already know the policy (previously downloaded); or // we try to download the policy if (!IsDownloadingPolicy ()) { policy = CrossDomainPolicyManager.GetCachedWebPolicy (uri); if (policy == null) { // we'll download the policy *then* proceed to the requested URI policy = CrossDomainPolicyManager.PolicyDownloadPolicy; Uri silverlight_policy_uri = CrossDomainPolicyManager.GetSilverlightPolicyUri (uri); BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal (null, silverlight_policy_uri); return preq.BeginGetResponse (new AsyncCallback (SilverlightPolicyCallback), preq); } } // Console.WriteLine ("{0} '{1}' using policy: {2}", method, uri, policy); HttpWebRequest wreq = GetHttpWebRequest (uri); wreq.Method = method; // store exception, to throw later, if we have no policy or are not allowed by the policy if ((policy == null) || !policy.IsAllowed (wreq)) { if ((policy == null) || (policy.Exception == null)) async_result.Exception = new SecurityException (); else async_result.Exception = policy.Exception; async_result.SetComplete (); return async_result; } // new in SL4 - unlike others it can be set (earlier) and is not checked later (CheckProtocolViolation) // but still throws a SecurityException here if (Headers.ContainsKey ("Proxy-Authorization")) throw new SecurityException (); if (!sendHeaders) wreq.Headers.Clear (); wreq.progress = progress; return wreq.BeginGetResponse (new AsyncCallback (EndCallback), wreq); }