码迷,mamicode.com
首页 > 其他好文 > 详细

Post/Get

时间:2016-07-05 18:26:23      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

        /// <summary>
        /// post请求
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="data">数据</param>
        /// <returns>返回响应的数据</returns>
        public string POST(string url, string data)
        {
            string respMsg = string.Empty;
            byte[] postData = Encoding.UTF8.GetBytes(data);
            WebClient webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            try
            {
                byte[] responseData = webClient.UploadData(url, "POST", postData);
                respMsg = Encoding.UTF8.GetString(responseData);
            }
            catch (WebException web_Error)
            {
                respMsg += "ERROR:" + web_Error.StackTrace + web_Error.Message;
            }
            catch (Exception e)
            {
                respMsg += "ERROR:" + e.StackTrace + e.Message;
            }

            return respMsg;
        }

 

Post/Get

标签:

原文地址:http://www.cnblogs.com/LJC-Home/p/5644339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!