private HttpResponseMessage get(String uri, Dictionary <string, string> parameters = null) { try { String fullURL = _baseUrl + uri; _httpClient.DefaultRequestHeaders.Clear(); _httpClient.DefaultRequestHeaders.Add("x-accept-version", BITPAY_API_VERSION); _httpClient.DefaultRequestHeaders.Add("x-bitpay-plugin-info", BITPAY_PLUGIN_INFO); if (parameters != null) { fullURL += "?"; foreach (KeyValuePair <string, string> entry in parameters) { fullURL += entry.Key + "=" + entry.Value + "&"; } fullURL = fullURL.Substring(0, fullURL.Length - 1); String signature = KeyUtils.sign(_ecKey, fullURL); _httpClient.DefaultRequestHeaders.Add("x-signature", signature); _httpClient.DefaultRequestHeaders.Add("x-identity", KeyUtils.bytesToHex(_ecKey.PubKey)); } var result = _httpClient.GetAsync(fullURL).Result; return(result); } catch (Exception ex) { throw new BitPayException("Error: " + ex.ToString()); } }
private HttpResponseMessage post(String uri, String json, bool signatureRequired = false) { try { var bodyContent = new StringContent(this.unicodeToAscii(json)); _httpClient.DefaultRequestHeaders.Clear(); _httpClient.DefaultRequestHeaders.Add("x-accept-version", BITPAY_API_VERSION); _httpClient.DefaultRequestHeaders.Add("x-bitpay-plugin-info", BITPAY_PLUGIN_INFO); bodyContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); if (signatureRequired) { String signature = KeyUtils.sign(_ecKey, _baseUrl + uri + json); _httpClient.DefaultRequestHeaders.Add("x-signature", signature); _httpClient.DefaultRequestHeaders.Add("x-identity", KeyUtils.bytesToHex(_ecKey.PubKey)); } var result = _httpClient.PostAsync(uri, bodyContent).Result; return(result); } catch (Exception ex) { throw new BitPayException("Error: " + ex.ToString()); } }