示例#1
0
        private async Task <string> ExecutePostAsync(string path, Dictionary <string, string> paramaters = null)
        {
            var url = ConfigurationManager.AppSettings["Ice3XUrl"];

            var queryString    = string.Empty;
            var keyValueParams = new List <KeyValuePair <string, string> >();

            if (paramaters != null)
            {
                queryString = QueryStringBuilder.BuildQueryString(paramaters);

                foreach (var paramatersKey in paramaters.Keys)
                {
                    keyValueParams.Add(new KeyValuePair <string, string>(paramatersKey, paramaters[paramatersKey]));
                }
            }

            using (var httpClient = new HttpClient())
            {
                var timeStamp = UnixTimeNow();
                var uri       = new Uri(string.Format($"{url}{path}"));
                var signature = SignMessage(queryString);

                var requestContent = new FormUrlEncodedContent(keyValueParams);

                using (var request = new HttpRequestMessage
                {
                    RequestUri = uri,
                    Method = HttpMethod.Post,
                    Content = requestContent
                })
                {
                    request.Headers.Add("accept-charset", "utf-8");
                    request.Headers.Add("sign", signature);
                    request.Headers.Add("key", _publicKey);
                    request.Headers.Add("timestamp", timeStamp.ToString());

                    var response = await httpClient.SendAsync(request);

                    var responseContent = response.Content;

                    using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
                    {
                        return(await reader.ReadToEndAsync());
                    }
                }
            }
        }
示例#2
0
        private async Task <string> ExecuteGetAsync(string path, Dictionary <string, object> paramaters = null)
        {
            var url = ConfigurationManager.AppSettings["Ice3XUrl"];

            if (paramaters != null)
            {
                var queryString = QueryStringBuilder.BuildQueryString(paramaters);
                path = $"{path}?{queryString}";
            }

            using (var client = new WebClient())
            {
                var result = await client.DownloadStringTaskAsync(new Uri($"{url}{path}"));

                return(result);
            }
        }