Example #1
0
        private void RecreateWebRequest(Action <HttpWebRequest> action)
        {
            // we now need to clone the request, since just calling GetRequest again wouldn't do anything

            var newWebRequest = (HttpWebRequest)WebRequest.Create(Url);

            newWebRequest.Method = webRequest.Method;
            HttpRequestHelper.CopyHeaders(webRequest, newWebRequest);
            newWebRequest.Credentials = webRequest.Credentials;
            action(newWebRequest);

            if (postedData != null)
            {
                HttpRequestHelper.WriteDataToRequest(newWebRequest, postedData);
            }
            if (postedStream != null)
            {
                postedStream.Position = 0;
                using (var stream = newWebRequest.GetRequestStream())
                    using (var commpressedData = new GZipStream(stream, CompressionMode.Compress))
                    {
                        postedStream.CopyTo(commpressedData);

                        commpressedData.Flush();
                        stream.Flush();
                    }
            }
            webRequest = newWebRequest;
        }