Exemple #1
0
 public override void SynchronizeCookies(AsyncServiceClient client)
 {
     if (client.StoreCookies && client.ShareCookiesWithBrowser && !client.EmulateHttpViaPost)
     {
         // browser cookies must be set on the ui thread
         System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
         {
             var cookieHeader = client.CookieContainer.GetCookieHeader(new Uri(client.BaseUri));
             System.Windows.Browser.HtmlPage.Document.Cookies = cookieHeader;
         });
     }
 }
        public static void SynchronizeCookies(this AsyncServiceClient client)
        {
#if SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
            if (client.StoreCookies && client.ShareCookiesWithBrowser && !client.EmulateHttpViaPost)
            {
                // browser cookies must be set on the ui thread
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => {
                    var cookieHeader = client.CookieContainer.GetCookieHeader(new Uri(client.BaseUri));
                    System.Windows.Browser.HtmlPage.Document.Cookies = cookieHeader;
                });
            }
#endif
        }
        internal static HttpWebRequest CreateHttpWebRequest(this AsyncServiceClient client, string requestUri)
        {
            var webRequest = PclExport.Instance.CreateWebRequest(requestUri);

            if (client.StoreCookies)
            {
                PclExportClient.Instance.SetCookieContainer(webRequest, client);
            }
            if (client.DisableAutoCompression)
            {
                client.Headers.Remove(HttpRequestHeader.AcceptEncoding.ToString());
            }

            return(webRequest);
        }
        public override void SetCookieContainer(HttpWebRequest webRequest, AsyncServiceClient client)
        {
            if (!client.EmulateHttpViaPost)
            {
                if (client.ShareCookiesWithBrowser)
                {
                    if (client.CookieContainer == null)
                    {
                        client.CookieContainer = new CookieContainer();
                    }
                    client.CookieContainer.SetCookies(webRequest.RequestUri, System.Windows.Browser.HtmlPage.Document.Cookies);
                }
            }

            webRequest.CookieContainer = client.CookieContainer;
        }
Exemple #5
0
        internal static HttpWebRequest CreateHttpWebRequest(this AsyncServiceClient client, string requestUri)
        {
            var webRequest = WebRequest.CreateHttp(requestUri);

            PclExport.Instance.Config(webRequest);

            if (client.StoreCookies)
            {
                PclExportClient.Instance.SetCookieContainer(webRequest, client);
            }

            if (!client.DisableAutoCompression)
            {
                PclExport.Instance.AddCompression(webRequest);
            }

            return(webRequest);
        }
        internal static HttpWebRequest CreateHttpWebRequest(this AsyncServiceClient client, string requestUri)
        {
#if SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
            var creator = client.EmulateHttpViaPost
                ? System.Net.Browser.WebRequestCreator.BrowserHttp
                : System.Net.Browser.WebRequestCreator.ClientHttp;

            var webRequest = (HttpWebRequest)creator.Create(new Uri(requestUri));

            if (client.StoreCookies && !client.EmulateHttpViaPost)
            {
                if (client.ShareCookiesWithBrowser)
                {
                    if (client.CookieContainer == null)
                    {
                        client.CookieContainer = new CookieContainer();
                    }
                    client.CookieContainer.SetCookies(new Uri(requestUri), System.Windows.Browser.HtmlPage.Document.Cookies);
                }

                webRequest.CookieContainer = client.CookieContainer;
            }
#else
            var webRequest = (HttpWebRequest)WebRequest.Create(requestUri);
            webRequest.MaximumResponseHeadersLength = int.MaxValue; //throws "The message length limit was exceeded" exception
            client.CancelAsyncFn = webRequest.Abort;

            if (client.StoreCookies)
            {
                webRequest.CookieContainer = client.CookieContainer;
            }
#endif

#if !SILVERLIGHT
            if (!client.DisableAutoCompression)
            {
                webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            }
#endif
            return(webRequest);
        }
Exemple #7
0
        protected ServiceClientBase()
        {
            this.HttpMethod = DefaultHttpMethod;
            asyncClient     = new AsyncServiceClient
            {
                ContentType        = ContentType,
                StreamSerializer   = AsyncSerializeToStream,
                StreamDeserializer = AsyncDeserializeFromStream,
                UserName           = this.UserName,
                Password           = this.Password,
                RequestFilter      = this.RequestFilter,
                ResponseFilter     = this.ResponseFilter
            };
            this.CookieContainer = new CookieContainer();
            this.StoreCookies    = true; //leave
            this.Headers         = new NameValueCollection();

#if SILVERLIGHT
            asyncClient.HandleCallbackOnUiThread = this.HandleCallbackOnUiThread = true;
            asyncClient.ShareCookiesWithBrowser  = this.ShareCookiesWithBrowser = true;
#endif
        }
Exemple #8
0
 public virtual void SynchronizeCookies(AsyncServiceClient client)
 {
 }
Exemple #9
0
 public virtual void SetCookieContainer(HttpWebRequest webRequest, AsyncServiceClient client)
 {
     webRequest.CookieContainer = client.CookieContainer;
 }