コード例 #1
0
        private static string GetResponseMessage(HttpWebResponse response) {
            if (response.IsSuccessful())
                return null;

            int statusCode = (int)response.StatusCode;
            string responseText = response.GetResponseText();
            string message = statusCode == 404 ? "404 Page not found." : responseText.Length < 500 ? responseText : "";

            if (responseText.Trim().StartsWith("{")) {
                try {
                    var responseJson = JObject.Parse(responseText);
                    message = responseJson["message"].Value<string>();
                } catch { }
            }

            return message;
        }
コード例 #2
0
 public static string ReadResponseText( HttpWebResponse webResponse )
 {
     return webResponse.GetResponseText();
 }
コード例 #3
0
 public static string ReadResponseText( HttpWebResponse webResponse, Encoding encoding )
 {
     return webResponse.GetResponseText( encoding );
 }
コード例 #4
0
 public RequestException(HttpWebResponse response)
     : base(string.Format("Request failed: {0} - {1}", response.StatusCode, response.StatusDescription))
 {
     Response = response;
     HttpStatus = response.StatusCode;
     HttpStatusDescription = response.StatusDescription;
     ResponseText = response.GetResponseText();
 }