private static string getContentType(HttpWebResponse response)
 {
     if (!String.IsNullOrEmpty(response.ContentType))
     {
         return(ContentType.GetMediaTypeFromHeaderValue(response.ContentType));
     }
     else
     {
         return(null);
     }
 }
Пример #2
0
        /// <summary>
        /// Converts a content type to a ResourceFormat
        /// </summary>
        /// <param name="contentType">The content type, as it appears on e.g. a Http Content-Type header</param>
        /// <returns></returns>
        public static ResourceFormat GetResourceFormatFromContentType(string contentType)
        {
            if (String.IsNullOrEmpty(contentType))
            {
                return(ResourceFormat.Unknown);
            }

            var f = ContentType.GetMediaTypeFromHeaderValue(contentType);

            if (JSON_CONTENT_HEADERS.Contains(f))
            {
                return(ResourceFormat.Json);
            }
            else if (XML_CONTENT_HEADERS.Contains(f))
            {
                return(ResourceFormat.Xml);
            }
            else
            {
                return(ResourceFormat.Unknown);
            }
        }
Пример #3
0
        /// <summary>
        /// Checks whether a given content type is valid as a content type for resource data
        /// </summary>
        /// <param name="contentType">The content type, as it appears on e.g. a Http Content-Type header</param>
        /// <returns></returns>
        public static bool IsValidResourceContentType(string contentType)
        {
            var f = ContentType.GetMediaTypeFromHeaderValue(contentType);

            return(JSON_CONTENT_HEADERS.Contains(f) || XML_CONTENT_HEADERS.Contains(f));
        }