C# http post 地址


        public static string PostData(string p_strUrl, string p_strData)
        {
            Encoding dataEncode;
            dataEncode = System.Text.Encoding.UTF8;

            byte[] byteArray = dataEncode.GetBytes(p_strData); //转化
            HttpWebRequest http = (HttpWebRequest)WebRequest.Create(p_strUrl);

            http.Method = "POST";

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

            Stream newStream = http.GetRequestStream();
            newStream.Write(byteArray, 0, byteArray.Length);//写入参数
            newStream.Close();

            HttpWebResponse response = (HttpWebResponse)http.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string strRec = sr.ReadToEnd();
            sr.Close();
            response.Close();
            return strRec;
        }

posted @ 2012-12-06 09:30  bert.zeng  阅读(313)  评论(0编辑  收藏  举报