首页 > 移动平台 > 详细

post请求 application/x‐www‐form‐urlencoded

时间:2021-04-24 20:43:56      阅读:29      评论:0      收藏:0      [点我收藏+]

 

/// <summary>
        /// post请求
        /// 请求方法的编码格式:application/x‐www‐form‐urlencoded
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public string PostApi(string url,string data) {
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "post";
            request.KeepAlive = true;
            byte[] buffer = encoding.GetBytes(data);
            request.ContentLength = buffer.Length;
            request.GetRequestStream().Write(buffer, 0, buffer.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string result = reader.ReadToEnd();
            return result;
        }

使用

string url="http://www.ssss.com";
string
datastr = "method=" + method + "&requestData=" + requestData + "&appKey=" + appKey ;string res = PostApi(url,datastr);

 

post请求 application/x‐www‐form‐urlencoded

原文:https://www.cnblogs.com/dyd520/p/14697487.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!