C#的post请求

        public string Query(string queryString)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(RequestURL);
            request.Method = "POST";
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] byteArray = encoding.GetBytes(queryString);

            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(byteArray, 0, byteArray.Length);
            WebResponse response = request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(responseStream);

            string result = sr.ReadToEnd();
            requestStream.Close();
            sr.Close();
            responseStream.Close();
            return result;
        }

 

C#的post请求

上一篇:win7安装telent


下一篇:C# web项目添加*.ashx文件后报错处理