请问怎么接收返回的XML文档

aqgsh 2010-05-18 03:14:11
请教您一个问题?我现在遇到这样一个情况,
比如说我需要提交这样一个网址:http://www.xxx.com/xxx.asp?a=2323&b=sdf&c=sdfsf


这个网址不管参数正确与否,都会返回一个XML的文档,请问我如何在提交这个网页后立即能获取到返回的XML,以便我进行判断!

大家有谁会的,请教了!谢谢!使用C#
本人第一次发帖,请大家关照!!
...全文
343 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
aqgsh 2010-05-18
  • 打赏
  • 举报
回复
10楼 hwj383 你好


我不需要输出xml代码,只要求进行判断,你的方法提示错误

无法按照请求设置空的或空白的方法。
参数名: value


行 78: 
行 79: HttpWebRequest request=(HttpWebRequest)HttpWebRequest.Create( "http://202.75.218.82/rsct/XQT_OnlineOrder.asp?merchantid=443155");
行 80: request.Method = "GET ";
行 81: request.ContentType = "text/xml ";
行 82: request.Timeout = 10000;
aqgsh 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 mohugomohu 的回复:]
用WebRequest啊
[/Quote]
能给个具体的代码吗?

http://202.75.218.82/rsct/XQT_OnlineOrder.asp

这个网址,需要接收的参数很多,随便传个参数,只要能接收返回的xml代码,并判断resultno和retmsg的值。
「已注销」 2010-05-18
  • 打赏
  • 举报
回复
发送端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace Http
{
class Program
{
static void Main(string[] args)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.xxx.com/xxx.asp?a=2323&b=sdf&c=sdfsf
");
request.Method = "POST";
request.ContentType = "text/xml";
request.Timeout = 10000;

byte[] b = Encoding.UTF8.GetBytes("hwj383");

using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(b, 0, b.Length);
requestStream.Close();
}

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Status OK");
}
else
{
Console.WriteLine("Status Faile");
}

Console.ReadLine();

}
}
}


接收端

        protected void Page_Load(object sender, EventArgs e)
{
//这里你自已构建一个XML文件输出出去就可以了
byte[] b = new byte[this.Request.InputStream.Length];
this.Request.InputStream.Read(b, 0, b.Length);
this.Response.StatusCode = 200;
this.Response.Write(this.Request.ContentEncoding.GetString(b));
this.Response.End();
}
mohugomohu 2010-05-18
  • 打赏
  • 举报
回复
用WebRequest啊
dlsgliss 2010-05-18
  • 打赏
  • 举报
回复
帮顶啊!
hugang001 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zxp8819 的回复:]
引用 2 楼 army369168520 的回复:
LZ的学习精神真是让人佩服,3点多了还编程。呵呵 向LZ学习!

膜拜.....
顶起
[/Quote]
一起膜拜....
纯膜拜而回。。。。
aqgsh 2010-05-18
  • 打赏
  • 举报
回复
三点多,后来我弄到五点,实在还是不行,找了好多资料,都不管用!没有人知道吗?
aqgsh 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 xk1126 的回复:]
解决了楼主接贴给分啊!
[/Quote]

我是第一次发贴的,你说我把分数给谁了?
铛铛 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 army369168520 的回复:]
LZ的学习精神真是让人佩服,3点多了还编程。呵呵 向LZ学习!
[/Quote]
膜拜.....
顶起
xk1126 2010-05-18
  • 打赏
  • 举报
回复
解决了楼主接贴给分啊!
RedFish2010 2010-05-18
  • 打赏
  • 举报
回复
ajax就可以吧
「已注销」 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 aqgsh 的回复:]
10楼 hwj383 你好


我不需要输出xml代码,只要求进行判断,你的方法提示错误

无法按照请求设置空的或空白的方法。
参数名: value


C# code
行 78:
行 79: HttpWebRequest request=(HttpWebRequest)HttpWebRequest.Create( "http://202.75.218.……
[/Quote]

你设置 request.Method 属性了吗?设对了吗?
army369168520 2010-05-18
  • 打赏
  • 举报
回复
LZ的学习精神真是让人佩服,3点多了还编程。呵呵 向LZ学习!
njw1028 2010-05-18
  • 打赏
  • 举报
回复
asp页面。
[code=VBScript]dim xmlDoc
xmlDoc.load(request)
[/code]
aqgsh 2010-05-18
  • 打赏
  • 举报
回复
唉!自己解决了!!!
        WebClient client = new WebClient();
Byte[] responseData =
client.DownloadData(@"http://202.75.218.82/rsct/XQT_OnlineOrder.asp?merchantid=103155&tranid=20101013113944");

string stockXML = System.Text.Encoding.Default.GetString(responseData).Replace("\r\n", "");
DataSet ds = new DataSet();
System.Xml.XmlTextReader oXmlReader = new XmlTextReader(new System.IO.StringReader(stockXML));

ds.ReadXml(oXmlReader);


this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();



高手如云的地方,居然还是自己解决了!无语!

110,534

社区成员

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

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

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