HttpWebRequest Post方式传值

来源:互联网 发布:ubuntu怎么安装输入法 编辑:程序博客网 时间:2024/05/23 17:15

HttpWebRequest   Post方式传值
{
 // string param = "UID=" + strUid + "&FunctionName=Survey";
            //string param = "UID=2fba7bf3-64fc-478b-8e71-178af0dcc548&FunctionName=Survey";           
            byte[] bs = Encoding.ASCII.GetBytes(param);
            //string strUrl =  @"http://202.142.26.39/GetFunctionList.aspx";
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
            req.Method = "POST";
            //req.Timeout = 10;
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = bs.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
            }
            HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
            Stream receiveStream = rep.GetResponseStream();
            Encoding encode = System.Text.Encoding.GetEncoding("UTF-8");
            StreamReader readStream = new StreamReader(receiveStream, encode);
            Char[] read = new Char[256];
            int count = readStream.Read(read, 0, 256);
            StringBuilder sb = new StringBuilder("");
            while (count > 0)
            {
                String readstr = new String(read, 0, count);
                sb.Append(readstr);
                count = readStream.Read(read, 0, 256);
            }
            rep.Close();
            readStream.Close();
            return sb.ToString();
            //    XmlDocument doc = new XmlDocument();
            //    string xml = sb.ToString();
            //  doc.LoadXml(xml);

原创粉丝点击