WriteDataToRequest() public static method

public static WriteDataToRequest ( HttpWebRequest req, string data ) : void
req System.Net.HttpWebRequest
data string
return void
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;
            HttpJsonRequestHelper.CopyHeaders(webRequest, newWebRequest);
            newWebRequest.Credentials = webRequest.Credentials;
            action(newWebRequest);

            if (postedData != null)
            {
                HttpJsonRequestHelper.WriteDataToRequest(newWebRequest, postedData);
            }
            if (postedStream != null)
            {
                postedStream.Position = 0;
                using (var stream = newWebRequest.GetRequestStream())
                {
                    postedStream.CopyTo(stream);
                    stream.Flush();
                }
            }
            webRequest = newWebRequest;
        }
Example #2
0
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        public void Write(string data)
        {
            postedData = data;

            HttpJsonRequestHelper.WriteDataToRequest(webRequest, data);
        }