private static string AddUrlParams(string url, object requestParams)
        {
            if (requestParams == null)
            {
                return(url);
            }
            string query = "";

            if (requestParams is string)
            {
                query = requestParams.ToString();
            }
            else
            {
                var keyValues = WebParamsUtils.ToKeyValuePairs(requestParams);
                query = DictToStr(keyValues, "&", true);
            }

            if (url.IndexOf("?") > 0)
            {
                url = url + '&' + query;
            }
            else
            {
                url = url + '?' + query;
            }
            return(url);
        }
        public static async Task <T> PostUrlEncodedAsync <T>(this HttpClient client, string url, object requestParams, IDictionary <string, string> headers = null)
        {
            var keyValues = WebParamsUtils.ToKeyValuePairs(requestParams);
            IDictionary <string, string> encodedParms = new Dictionary <string, string>();

            foreach (var item in keyValues)
            {
                encodedParms.Add(item.Key, item.Value?.ToString());
            }
            var content = new FormUrlEncodedContent(encodedParms);

            //等价于
            //var body = WebUtils.BuildQuery(keyValues,false);
            //var content = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded");
            //ByteArrayContent
            return(await PostAsync <T>(client, url, content, headers));
        }
        public static async Task <T> PostFileAsync <T>(this HttpClient client, string url, object requestParams, byte[] datas, string fileName, IDictionary <string, string> headers = null)
        {
            var keyValues = WebParamsUtils.ToKeyValuePairs(requestParams);
            MultipartFormDataContent content = new MultipartFormDataContent();

            foreach (var item in keyValues)
            {
                content.Add(new StringContent(item.Value?.ToString() ?? string.Empty), item.Key);
            }

            var fileContent = new ByteArrayContent(datas);

            fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");// = MediaTypeHeaderValue.Parse("audio/mp3");
            content.Add(fileContent, "file", fileName);

            return(await PostAsync <T>(client, url, content, headers));
        }