怎样用C#(asp.net)接收XML数据包(jsp),急,在线等,马上接

doutht 2006-07-18 03:12:47
怎样用C#(asp.net)接收XML数据包(jsp),急,在线等,马上接
(最好给出例子,谢谢)
...全文
616 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuhuabucai 2006-07-20
  • 打赏
  • 举报
回复
用老孟的就可以
batiraul 2006-07-20
  • 打赏
  • 举报
回复
XmlDocument 查MSDN。
doutht 2006-07-20
  • 打赏
  • 举报
回复
顶起来
还是没搞定啊
warfen 2006-07-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);
cat_hsfz 2006-07-20
  • 打赏
  • 举报
回复
就用XmlDocument.Load(Request.InputStream)也可以啊,至于XmlDocument如何使用,你可以查MSDN。
batiraul 2006-07-20
  • 打赏
  • 举报
回复
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);
真相重于对错 2006-07-20
  • 打赏
  • 举报
回复
using HttpWebRequest
ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconhttp.htm
doutht 2006-07-20
  • 打赏
  • 举报
回复
我又来了
doutht 2006-07-20
  • 打赏
  • 举报
回复
多谢各位,结帖
cat_hsfz 2006-07-19
  • 打赏
  • 举报
回复
你的JSP发过来是如何“发”?是指JSP以一般HTTP客户端的身份按POST方式发送请求给你的ASP.NET页面,而请求主体是XML吗?
pzhye 2006-07-19
  • 打赏
  • 举报
回复
大家帮忙啊
pzhye 2006-07-19
  • 打赏
  • 举报
回复
再顶起来
都无言了

因为工作上急用,我又不太熟悉asp.net
写了一点点,帮我看看后面怎么接收jsp文件的地址(比如http://123.456.789.0/jsp.jsp)

using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
Stream str =new Stream;
str = Request.InputStream
...............

}
}
孟子E章 2006-07-19
  • 打赏
  • 举报
回复
XmlDocument.Load(Request.InputStream )
pzhye 2006-07-19
  • 打赏
  • 举报
回复
不是读XXX.xml文件
是接收jsp文件发送过来的xml数据包
(pzhye也是我的帐号,是换个帐号顶)
tiaoci 2006-07-19
  • 打赏
  • 举报
回复
用 XmlDocument 对象吧,一样的
pzhye 2006-07-19
  • 打赏
  • 举报
回复
<%@ Language=VBScript %>
<%

Response.ContentType = "text/xml"
Response.CharSet = "GB2312"

dim xmldom
' set xmldom = Server.CreateObject("Microsoft.XMLDOM")
set xmldom = Server.CreateObject("MSXML.DOMDocument")
xmldom.load Request

xinxi1 = xmldom.selectSingleNode("//version").text
xinxi2 = xmldom.selectSingleNode("//customer").text
xinxi3 = xmldom.selectSingleNode("//pwd").text
xinxi4 = xmldom.selectSingleNode("//mobile").text
xinxi5 = xmldom.selectSingleNode("//msgid").text
xinxi6 = xmldom.selectSingleNode("//status").text

%>

<?xml version="1.0" encoding="gb2312" ?>
<tishi><%=retval%></tishi> <!--返回是否成功的的信息并在hh_post.asp页面显示-->
<feixian-mv-response>
<version>xinxi1</version>
<customer>xinxi2</customer>
<pwd><%=xinxi3%></pwd>
<mobile><%=xinxi4%></mobile>
<msgid><%=xinxi5%></msgid>
<status><%=xinxi6%></status>
</feixian-mv-response>

我知道asp的怎么写,可asp.net不会啊,大家帮忙吧
doutht 2006-07-19
  • 打赏
  • 举报
回复
怎么还是没有人帮忙呢
doutht 2006-07-19
  • 打赏
  • 举报
回复
顶一顶就回家了
pzhye 2006-07-19
  • 打赏
  • 举报
回复
难道真的没人救我吗
郁闷啊
分不是问题
谁能帮我解决啊
超级大笨狼 2006-07-19
  • 打赏
  • 举报
回复
XMLDocument
加载更多回复(8)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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