none
ASP.NET接收POST响应的xml数据 RRS feed

  • 问题

  • 我在Winform中写了一个POST请求一个asp.net页面的方法,现在要在ASP.NET页面中获取这个xml字符串[postData],并保存到数据库中。
            Winform的POST请求
            public void PostPage(string url,string postData, Encoding encoding)
            {
                HttpWebRequest request = null;
                Stream writer = null;
                try
                {
                    byte[] data = Encoding.Default.GetBytes(postData);
                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.Timeout = 60000;
                    request.AllowAutoRedirect = false;
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = data.LongLength;

                    writer = request.GetRequestStream();
                    writer.Write(data, 0, data.Length);
                    writer.Flush();
                }
                catch
                { }
                finally
                {
                    if (request != null) request = null;
                    if (response != null)
                    {
                        response.Close();
                        response = null;
                    }               
                    if(writer != null)
                    {
                        writer.Close();
                        writer = null;
                    }
                }
           
            }

    ASP.NET页面方法
    StreamReader stream = new StreamReader(Request.InputStream);
    string xml = stream.ReadToEnd();
    Response.Write(xml);

    是不是获取数据的方法不正确,没有办法获取Winform的请求,我发布到IIS里的,这里的Response.Write在我的程序里是一段数据库的访问操作。
    应该如何操作?

    2010年3月4日 2:04

答案

全部回复