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; }
/// <summary> /// Writes the specified data. /// </summary> /// <param name="data">The data.</param> public void Write(string data) { postedData = data; HttpJsonRequestHelper.WriteDataToRequest(webRequest, data); }