七色彩虹

勤奋、务实、团结、创新

导航

post流提交

Posted on 2010-11-16 12:41  aadfe  阅读(612)  评论(0编辑  收藏  举报

string m_QuestURL = "http://localhosts/service.ashx";

        //Post请求地址
        HttpWebRequest m_Request = (HttpWebRequest)WebRequest.Create(m_QuestURL);

        //相应请求的参数
        byte[] data = Encoding.GetEncoding("gb2312").GetBytes(m_Doc.OuterXml);
        m_Request.Method = "Post";
        m_Request.ContentType = "application/x-www-form-urlencoded";
        m_Request.ContentLength = data.Length;

        //请求流
        Stream requestStream = m_Request.GetRequestStream();
        requestStream.Write(data, 0, data.Length);
        requestStream.Close();

        //响应流
        HttpWebResponse m_Response = (HttpWebResponse)m_Request.GetResponse();
        Stream responseStream = m_Response.GetResponseStream();
        StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("gb2312"));
        //获取返回的信息
        string result = streamReader.ReadToEnd();

        streamReader.Close();
        responseStream.Close();