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; }
public static string ReadResponseText( HttpWebResponse webResponse ) { return webResponse.GetResponseText(); }
public static string ReadResponseText( HttpWebResponse webResponse, Encoding encoding ) { return webResponse.GetResponseText( encoding ); }
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(); }