http请求数据

        /// <summary>
        /// http请求post数据
        /// </summary>
        /// <param name="postData">数据</param>
        /// <param name="url">url</param>
        private void httppostdata(string postData, string url)
        {
            WebRequest request = WebRequest.Create(url);
            request.Method = "Post";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = string.IsNullOrWhiteSpace(postData) ? 0 : Encoding.UTF8.GetByteCount(postData);
            StreamWriter sw = new StreamWriter(request.GetRequestStream(), new UTF8Encoding(false));
            sw.Write(postData);
            sw.Flush();
            sw.Dispose();
            sw.Close();
        }

posted @ 2016-07-12 22:49  change_4_now  阅读(195)  评论(0编辑  收藏  举报