当前位置:编程学习 > C#/ASP.NET >>

服务器接收httpwebrequest post的数据问题

使用httpwebrequest  post数据到服务器,只能使用request.inputstream来接收,然后自行解析吗?
使用request.form接收不到任何数据。。。

请指导,谢谢~
代码
        string url="http://xxxx.com/test.aspx";
        string content = "content=" + HttpUtility.UrlEncodeUnicode("this is a sentence.");
        byte[] data = Encoding.UTF8.GetBytes(content);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        request.ContentLength = data.Length;
        request.ContentType = "text/html";

        Stream sw= request.GetRequestStream();
        sw.Write(data, 0, data.Length);
        sw.Close();

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream sr = response.GetResponseStream();
        StreamReader reader = new StreamReader(sr);
        string resultJson=reader.ReadToEnd();
        reader.Close();
        sr.Close();
        response.Close();

服务器端使用下边的方式得不到任何数据
            NameValueCollection coll = Request.Form;
            string[] requestarr = coll.AllKeys;

使用 Stream s = Request.InputStream;
            StreamReader sr = new StreamReader(s);
            string inputstream=sr.ReadToEnd();
            sr.Close();
可以得到post来的数据,可是需要自行解析,比较麻烦。。。

有没有比较好的方法?
--------------------编程问答-------------------- 除 --------------------编程问答-------------------- 有没有大侠帮下忙啊~ --------------------编程问答-------------------- 听不懂。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,