怎样用C#(asp.net)接收XML数据包(jsp)

22 楼Batiraul(Bati4Ever)回复于 2006-07-20 09:20:16 得分 4

net_lover(孟子E章)   (   )   信誉:140    
  XmlDocument.Load(Request.InputStream   )  
   
  用老孟的就可以,前提是jsp   页面要把xml数据包post   到你的aspx页面.  
   
  XmlDocument   httpxml=new   XmlDocument();  
  string   MyString   =DebugXmlPath+   "jsppost"+   MyDate.ToString("yyyyMMddHHmmfffffff")+".xml";  
  httpxml.Load(Request.InputStream);  
  httpxml.Save(MyString);  
 

24 楼warfen(学无止境)回复于 2006-07-20 09:35:40 得分 20

[Asp.net   Post]  
  public   string   PostTo(string   Request,   Uri   destination)  
  {  
  byte[]   requestBytes   =   Encoding.GetEncoding("GB2312").GetBytes(Request);  
  //   Build   the   request.  
  HttpWebRequest   webRequest   =   (HttpWebRequest)WebRequest.Create(destination);  
  webRequest.ContentType   =   "application/x-www-form-urlencoded";  
  webRequest.Method   =   "POST";  
  webRequest.ContentLength   =   requestBytes.Length;  
   
  //   Write   the   request  
  Stream   reqStream   =   webRequest.GetRequestStream();  
  reqStream.Write(requestBytes,0,requestBytes.Length);  
  reqStream.Close();  
  //   Get   a   response  
  HttpWebResponse   webResponse   =   (HttpWebResponse)webRequest.GetResponse();  
  if   (webRequest.HaveResponse)  
  {  
  //   Read   response  
  StreamReader   stream   =   new   StreamReader(webResponse.GetResponseStream(),System.Text.Encoding.GetEncoding("gb2312"));  
  string   responseString   =   stream.ReadToEnd();  
  stream.Close();  
   
  webResponse.Close();  
  return   responseString;  
  }  
  //   No   response  
  throw   new   ApplicationException("No   response   received   from   host.");  
  }  
   
  [Asp.net   Get]  
  HttpWebRequest   webRequest   =   (HttpWebRequest)WebRequest.Create(new   Uri(destination));  
  webRequest.Accept   =   "*/*";  
  webRequest.AllowAutoRedirect   =   false;  
  webRequest.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.0;   Windows   NT   5.0;   .NET   CLR   1.0.3705)";  
  webRequest.ContentType   =   "text/xml";  
  webRequest.Method   =   "GET";  
   
  HttpWebResponse   webResponse   =   (HttpWebResponse)webRequest.GetResponse();  
  StreamReader   sreader   =   new   StreamReader(webResponse.GetResponseStream());  
  response   =   sreader.ReadToEnd();  
   
  //响应倒入XmlDocument  
  XmlDocument   dom   =   new   XmlDocument();  
  dom.LoadXml(response);  
   
  //添加Xml的XPath解析  
  XmlNamespaceManager   m   =   new   XmlNamespaceManager(dom.NameTable);  
  m.AddNamespace("**","***");//添加解析  
  m.addNamespace(...);  
   
  //获取Xml节点  
  XmlNode   node   =   dom.SelectSingleNode(xpath,context);  

你可能感兴趣的:(xml,jsp,String,Stream,C#,asp.net)