xml文件的发送和接收

来源:互联网 发布:查航班软件 编辑:程序博客网 时间:2024/05/18 10:08

/// <summary>
        /// 提交请求
        /// </summary>
        /// <param name="xmlRequest"></param>
        /// <returns></returns>
        public string PostRequest(string xmlRequest, string url, string apiKey)
        {
            string xml = xmlRequest;
            xmlRequest = GetEncryptString(xmlRequest, apiKey);
            Logger.LogInfo("发送请求" + xmlRequest);
            Encoding encoding = Encoding.GetEncoding("utf-8");
            WebRequest request = WebRequest.Create(url);
            request.Method = "POST";
            byte[] postdata = encoding.GetBytes(xmlRequest);
            request.ContentLength = postdata.Length;
            Stream requesstream = request.GetRequestStream();
            requesstream.Write(postdata, 0, postdata.Length);
            requesstream.Close();
            WebResponse response = request.GetResponse();
            StreamReader responsestream = new StreamReader(response.GetResponseStream(), encoding);
            string html = responsestream.ReadToEnd();
            requesstream.Close();
            response.Close();
            Logger.LogInfo("接收报文:" + html);
            return html;
        }

 

 

该代码是发送一个xml文件

 

 

   StreamReader sr = new StreamReader(Request.InputStream);
    string strInput = sr.ReadToEnd();

    this._request = XmlUtil.DeXmlSerialization(typeof(message), this._xml) as message;

 

 

只是接收的 接收到数据后通过反序列化 得到对象