.NET XML POST 请求

//请求体,XML参数
            string xmlstring = @"<root></root>“;
            //请求URL
            string postUrl ="http://localhost:3020/Data/Test";  //上传xml,对方的url  
            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(postUrl);
            //Request.CookieContainer = "";  
            Request.Method = "POST";
            Request.ContentType = "application/x-www-form-urlencoded";
            Request.AllowAutoRedirect = true;
            //    string strXML = "XMLDATA=<book><author>Irina</author><title>Piano Fort A</title><price>4.95</price></book>";  
            string strXML = xmlstring;
            byte[] data = Encoding.UTF8.GetBytes(strXML);
            Stream newStream = Request.GetRequestStream();
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            HttpWebResponse response = (HttpWebResponse)Request.GetResponse();
            Stream stream = null;
            stream = response.GetResponseStream();
            StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default, true);
            string file = reader.ReadToEnd();

 

posted on 2017-02-14 10:12  CodeArtist  阅读(300)  评论(0编辑  收藏  举报