public static QueryStringToJson ( string query ) : string | ||
query | string | The query string. |
return | string |
/// <summary> /// Makes an HTTP POST request to an endpoint URI with the passed parameters and returns the response. /// </summary> /// <typeparam name="T">The strong type of the HTTP response we are deserializing.</typeparam> /// <param name="endpoint">The endpoint URI where to make the request to.</param> /// <param name="parameters">The query string parameters, if any.</param> /// <returns>The HTTP response, deserialized into the strong type <typeparamref name="T"/>.</returns> private T HttpPost <T>(string endpoint, string parameters) where T : class, IHttpResponse, new() { T result; string responseText; try { byte[] bytes = Encoding.ASCII.GetBytes(parameters); WebRequest request = WebRequest.Create(endpoint); request.Timeout = 300 * 1000; request.ContentType = Shared.PostMimeType; request.Method = Shared.PostMethod; request.ContentLength = bytes.Length; Stream stream = request.GetRequestStream(); stream.Write(bytes, 0, bytes.Length); stream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); responseText = response.GetResponseString(); string json = Utility.QueryStringToJson(responseText); result = json.DeserializeJson <T>(); result.Dynamic = json.DeserializeJson(); } catch (WebException web) { result = new T(); try { WebResponse response = web.Response; if (response.ContentType == Utility.JsonMimeType) { responseText = response.GetResponseString(); result.Exception = new BridgeException(Error.AccessingApiEndpoint.FormatWith(endpoint), web); result.Dynamic = responseText.DeserializeJson(); } else { result.Exception = new BridgeException(Error.AccessingApiEndpoint.FormatWith(endpoint), web); } } catch (Exception e) { result.Exception = new BridgeException(Error.ExceptionAccessingApiEndpoint.FormatWith(endpoint), e); } } return(result); }