C#中MSXML2的responseXml问题,以及Session传递问题

maconelxp 2004-12-20 05:18:00

///======================in C# writeSession.aspx
///Session("loginID") == "tmp";
MSXML2.XMLHTTPClass xmlHttp = new XMLHTTPClass();
try
{
XmlDocument xmlDom = new XmlDocument();
xmlDom.loadXml("<root loginID=\""+ Session("loginID")+ "\"/>");
string Url = Request.ServerVariables["Http_Host"];
Url = "http://" + Url + "/loginx/getDataXml.asp";
string xml = xmlDom.OuterXml;

xmlHttp.open("post",Url,false,null,null);
xmlHttp.send(xmlDom.OuterXml);

//请看这里
//Response.Write(xmlHttp.responseXml);
//上行代码得到的结果是 :System._ComObject;
//但是我想使用xmlDom.loadXml(xmlHttp.responseXml); 显然这是不行的
//现在我用的是:xmlDom.loadXml(xmlHttp.responseText);
//但是我不知道xmlHttp.responseXml可以干什么用,高手请回答
}
///======================in C#

'///======================in /loginx/getDataXml.asp
Dim XmlDom,Node
set XmlDom = Server.CreateObject("Microsoft.XmlDom")
XmlDom.Load Request
Set Node = XmlDom.SelectSingleNode("//root")
If TypeName(Node) <>"Nothing" then
Session("LoginID") = Node.getAttribute("loginID")
End If
Response.ContentType = "text/xml"
Response.Write "<?xml version=""1.0"" encoding=""gb2312""?>"
Response.Write "<root returnStr=""Session("LoginID")""/>"
Set XmlDom = Nothing

'===================现在如果用.net调试 http://localhost/writeSession.aspx的话,可以从那个asp文件里得到Session = "tmp",
'===================现在我如果在IE的地址栏里输入http://localhost/loginx/getDataXml.asp
'===================这时候我得到的Session却是空的,什么都没有
'===================不知道为什么,高手请回答,我该怎么样才能把Session从aspx传到asp里


...全文
289 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
b3b4s3d4 2004-12-25
  • 打赏
  • 举报
回复
//但是我想使用xmlDom.loadXml(xmlHttp.responseXml); 显然这是不行的
---------------
responseXml返回的不是string,而是一个XMlDocument,所以xmlDom.load(xmlHttp.responseXml);就可以了。或者xmlDom.loadXml(xmlHttp.responseXml.outerXML);
maconelxp 2004-12-25
  • 打赏
  • 举报
回复
up
tengjian1981 2004-12-25
  • 打赏
  • 举报
回复
up
asam2183 2004-12-25
  • 打赏
  • 举报
回复
既然用.NET开发,建议使用.NET的方法:

try
{
XmlDocument xmlDom = new XmlDocument();
xmlDom.loadXml("<root loginID=\""+ Session("loginID")+ "\"/>");
string strUrl = Request.ServerVariables["Http_Host"];
strUrl = "http://" + Url + "/loginx/getDataXml.asp";

WebRequest wReq = WebRequest.Create(strUrl);
wReq.Timeout = 15000;
WebResponse myWebResponse = wReq.GetResponse();

Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader( ReceiveStream, encode );

Char[] read = new Char[myWebResponse.ContentLength];
int count = readStream.Read( read, 0, Convert.ToInt32(myWebResponse.ContentLength-1));

String str ="";
while (count > 0)
{
str += new String(read, 0, count);
count = readStream.Read(read, 0, 256);
}

readStream.Close();
myWebResponse.Close();

return str;
}
catch(Exception er)
{
Console.Write(er.Message);
return er.Message ;
}
maconelxp 2004-12-22
  • 打赏
  • 举报
回复
up
wangxt 2004-12-21
  • 打赏
  • 举报
回复
帮你顶
lucbesson 2004-12-21
  • 打赏
  • 举报
回复
高难度

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧