void LoadContent(HttpWebRequest httpRequest, XPathHttpBody body) { long contentLength = body.PrepareContent(this.ItemFactory, this.Resolver); if (contentLength > 0) { httpRequest.ContentLength = contentLength; httpRequest.ContentType = body.MediaType; using (Stream contentStream = body.GetContentStream(), requestStream = httpRequest.GetRequestStream()) { contentStream.CopyTo(requestStream); } } }
XPathHttpResponse GetResponse(HttpWebResponse httpResponse) { XPathHttpResponse response = new XPathHttpResponse { Status = httpResponse.StatusCode, Message = httpResponse.StatusDescription, Headers = { httpResponse.Headers } }; if (httpResponse.ContentLength > 0) { string mediaType = ""; try { ContentType contentType = new ContentType(httpResponse.ContentType); mediaType = contentType.MediaType; } catch (FormatException) { } catch (ArgumentException) { } if (MediaTypes.IsMultipart(mediaType)) { XPathHttpMultipart multipart = new XPathHttpMultipart { MediaType = mediaType }; using (Stream responseBody = httpResponse.GetResponseStream()) multipart.Deserialize(responseBody, this.StatusOnly); response.Multipart = multipart; } else { XPathHttpBody body = new XPathHttpBody { MediaType = mediaType }; if (!String.IsNullOrEmpty(httpResponse.CharacterSet)) { try { body.Encoding = Encoding.GetEncoding(httpResponse.CharacterSet); } catch (ArgumentException) { } } if (!this.StatusOnly) { using (Stream responseBody = httpResponse.GetResponseStream()) body.Deserialize(responseBody, httpResponse.ResponseUri, this.ItemFactory, this.OverrideMediaType); } response.Body = body; } } return response; }