Request.InputStream 将数据作为XML数据发送
生活随笔
收集整理的這篇文章主要介紹了
Request.InputStream 将数据作为XML数据发送
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
將數(shù)據(jù)作為XML數(shù)據(jù)發(fā)送,例如:
public?voidPostXml(stringurl,?stringxml){????byte[]?bytes?=?Encoding.UTF8.GetBytes(xml);????HttpWebRequest?request?=?(HttpWebRequest)?WebRequest.Create(url);????request.Method?=?"POST";????request.ContentLength?=?bytes.Length;????request.ContentType?=?"text/xml";????using?(Stream?requestStream?=?request.GetRequestStream())?{??????requestStream.Write(bytes,?0,?bytes.Length);????}????HttpWebResponse?response?=?(HttpWebResponse)?request.GetResponse();????if?(response.StatusCode?!=?HttpStatusCode.OK)?{??????string?message?=?String.Format("POST?failed.?Received?HTTP?{0}",??????response.StatusCode);??????throw?new?ApplicationException(message);????}?}接收端通過Request.InputStream讀取:
byte[]?byts?=?new?byte[Request.InputStream.Length];Request.InputStream.Read(byts,0,byts.Length);stringreq?=System.Text.Encoding.Default.GetString(byts);req?=Server.UrlDecode(req);對于完整的XML數(shù)據(jù),可以:?
xmlDoc?=?newXmlDocument();xmlDoc.load(Request.InputStream);總結(jié)
以上是生活随笔為你收集整理的Request.InputStream 将数据作为XML数据发送的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 互联网投资是什么
- 下一篇: 美国三大股指均跌近5% 道指暴跌逾14