예제 #1
0
 /// <summary>
 /// 执行HTTP POST请求。
 /// </summary>
 /// <param name="client"></param>
 /// <param name="url">请求地址</param>
 /// <param name="dictionary">请求参数</param>
 /// <returns>HTTP响应</returns>
 public static async Task <string> DoPostAsync(this HttpClient client, string url, IDictionary <string, string> dictionary)
 {
     using (var requestContent = new StringContent(AlipayUtility.BuildQuery(dictionary), Encoding.UTF8, "application/x-www-form-urlencoded"))
         using (var response = await client.PostAsync(url, requestContent))
             using (var responseContent = response.Content)
             {
                 return(await responseContent.ReadAsStringAsync());
             }
 }
예제 #2
0
        /// <summary>
        /// 执行HTTP GET请求。
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url">请求地址</param>
        /// <param name="dictionary">请求参数</param>
        /// <returns>HTTP响应</returns>
        public static async Task <string> DoGetAsync(this HttpClient client, string url, IDictionary <string, string> dictionary)
        {
            if (url.Contains("?"))
            {
                url = url + "&" + AlipayUtility.BuildQuery(dictionary);
            }
            else
            {
                url = url + "?" + AlipayUtility.BuildQuery(dictionary);
            }

            using (var response = await client.GetAsync(url))
                using (var responseContent = response.Content)
                {
                    return(await responseContent.ReadAsStringAsync());
                }
        }