搜索
您的当前位置:首页正文

C# 后台模拟Post Xml数据 并接受

来源:易榕旅网

发送端:

//xmlDstUrl:发送的Url
//xmlContent:发送内容
                 try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(xmlDstUrl);
                    byte[] requestContent = System.Text.Encoding.ASCII.GetBytes(xmlContent);

                    myRequest.Method = "POST";
                    myRequest.ContentType = "text/xml";
                    myRequest.ContentLength = requestContent.Length;
                    System.IO.Stream requestStream = myRequest.GetRequestStream();
                    requestStream.Write(requestContent, 0, requestContent.Length);
                    requestStream.Close();

                    isSuccess = true;
                }
                catch (System.Exception ex)
                {
                    isSuccess = false;
                }

接收端:
        if (Request.InputStream.Length > 0)
        {
            byte[] bytes = new byte[Request.InputStream.Length];
            Request.InputStream.Read(bytes, 0, bytes.Length);
            FileStream fs = new FileStream(Request.PhysicalApplicationPath + "File.txt", FileMode.Create);
            fs.Write(bytes, 0, bytes.Length);
            fs.Flush();
            fs.Close();
        }

因篇幅问题不能全部显示,请点此查看更多更全内容

Top