Example #1
0
        /// <summary>
        /// Sends a GET request to Checkmarx REST API at the requestUri given. If NameValuePairs is given, then this will
        /// appended to the query string for the call.
        /// </summary>
        /// <param name="requestUri">Request URI</param>
        /// <param name="nameValuePairs">Name Value Pairs (parameter names and values)</param>
        /// <returns></returns>
        async Task <HttpResponseMessage> Get(string requestUri, NameValuePairs nameValuePairs = null)
        {
            if (!requestUri.StartsWith(CX_REST_API))
            {
                requestUri = String.Format("{0}{1}", CX_REST_API, requestUri);
            }

            if (nameValuePairs != null)
            {
                requestUri += "?" + nameValuePairs.ToQueryString();
            }

            Uri uri = new Uri(Client.BaseAddress, requestUri);

            Log.Debug(String.Format("Sending HTTP GET request to {0}.", uri));
            HttpResponseMessage response = await Client.GetAsync(uri);

            response.EnsureSuccessStatusCode();

            return(response);
        }
Example #2
0
        /// <summary>
        /// Sends a HTTP PUT request to the server at the requestUri given. This will append the given
        /// name value pairs into the body of the request as JSON.
        /// </summary>
        /// <param name="requestUri">Request URI</param>
        /// <param name="nameValuePairs">Name value pairs which will be sent in the body of the request as JSON.</param>
        /// <returns>Response from the server if the status code is 200</returns>
        async Task <HttpResponseMessage> Put(string requestUri, NameValuePairs nameValuePairs)
        {
            StringContent content = new StringContent(nameValuePairs.ToJson(), Encoding.UTF8, "application/json");

            return(await Put(requestUri, content));
        }