private RestReturnType CheckReturnType(HttpResponseMessage response) { if (null == response) { throw new ArgumentNullException("response"); } RestReturnType rt = RestReturnType.Detect; string contentType = ContentHelper.GetContentType(response); if (string.IsNullOrEmpty(contentType)) { rt = RestReturnType.Detect; } else if (ContentHelper.IsJson(contentType)) { rt = RestReturnType.Json; } else if (ContentHelper.IsXml(contentType)) { rt = RestReturnType.Xml; } return(rt); }
/// <summary> /// Reads the response content from the web response. /// </summary> protected void InitializeContent() { string contentType = ContentHelper.GetContentType(BaseResponse); if (ContentHelper.IsText(contentType)) { Encoding encoding = null; // fill the Content buffer string characterSet = WebResponseHelper.GetCharacterSet(BaseResponse); if (string.IsNullOrEmpty(characterSet) && ContentHelper.IsJson(contentType)) { characterSet = Encoding.UTF8.HeaderName; } this.Content = StreamHelper.DecodeStream(RawContentStream, characterSet, out encoding); this.Encoding = encoding; } else { this.Content = string.Empty; } }
private RestReturnType CheckReturnType(WebResponse response) { if (response == null) { throw new ArgumentNullException("response"); } RestReturnType detect = RestReturnType.Detect; string contentType = ContentHelper.GetContentType(response); if (string.IsNullOrEmpty(contentType)) { return(RestReturnType.Detect); } if (ContentHelper.IsJson(contentType)) { return(RestReturnType.Json); } if (ContentHelper.IsXml(contentType)) { detect = RestReturnType.Xml; } return(detect); }