Ejemplo n.º 1
0
        XPathHttpResponse GetResponse(HttpWebResponse httpResponse)
        {
            var response = new XPathHttpResponse {
                Status  = httpResponse.StatusCode,
                Message = httpResponse.StatusDescription,
                Headers = { httpResponse.Headers }
            };

            if (httpResponse.ContentLength > 0)
            {
                string mediaType = "";

                try {
                    var contentType = new ContentType(httpResponse.ContentType);
                    mediaType = contentType.MediaType;
                } catch (FormatException) {
                } catch (ArgumentException) {
                }

                if (MediaTypes.IsMultipart(mediaType))
                {
                    var multipart = new XPathHttpMultipart {
                        MediaType = mediaType
                    };

                    using (Stream responseBody = httpResponse.GetResponseStream()) {
                        multipart.Deserialize(responseBody, this.StatusOnly);
                    }

                    response.Multipart = multipart;
                }
                else
                {
                    var 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);
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        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);
            }
             }
        }
Ejemplo n.º 4
0
        XPathHttpResponse GetResponse(HttpWebResponse httpResponse)
        {
            var response = new XPathHttpResponse {
            Status = httpResponse.StatusCode,
            Message = httpResponse.StatusDescription,
            Headers = { httpResponse.Headers }
             };

             if (httpResponse.ContentLength > 0) {

            string mediaType = "";

            try {
               var contentType = new ContentType(httpResponse.ContentType);
               mediaType = contentType.MediaType;

            } catch (FormatException) {
            } catch (ArgumentException) {
            }

            if (MediaTypes.IsMultipart(mediaType)) {

               var multipart = new XPathHttpMultipart {
                  MediaType = mediaType
               };

               using (Stream responseBody = httpResponse.GetResponseStream()) {
                  multipart.Deserialize(responseBody, this.StatusOnly);
               }

               response.Multipart = multipart;

            } else {

               var 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;
        }