狂急的一个问题,比较难哦,渴望高手回答,在线==~~~

aaaa250 2006-01-23 09:52:22
我的客户端是WIN FORM,现在我要通过HTTP请求头形式将参数给JAVA的SERVLET服务器,服务器给我返回一个XML形式的HTTP,我在客户端接收,用datagrid把数据显示出来,我用.net怎么实现客户端的功能??
...全文
265 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
aaaa250 2006-01-23
  • 打赏
  • 举报
回复
好的,还是要谢谢~
真相重于对错 2006-01-23
  • 打赏
  • 举报
回复
sorry , 因为你的xml具体是什么我不清楚,没法给你写代码了
还是给你个msdn的例子吧
ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconxmldataset.htm
aaaa250 2006-01-23
  • 打赏
  • 举报
回复
谢谢 hdt(倦怠) ,XML得到了,怎么转成DATASET,最好是C#的
真相重于对错 2006-01-23
  • 打赏
  • 举报
回复
System.Net.HttpWebRequest wbq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create( "http://www.163.com?id=1" );
System.Net.HttpWebResponse wbr = (System.Net.HttpWebResponse)wbq.GetResponse();
Stream stream = wbr.GetResponseStream();
int nCount = (int)wbr.ContentLength;
byte[] b = new byte[nCount];
stream.Read( b , 0 , nCount );
string str = System.Text.Encoding.Default.GetString( b , 0 , nCount );
str 就是xml内容
aaaa250 2006-01-23
  • 打赏
  • 举报
回复
非常感谢hdt(倦怠) ,我很菜,你写的代码,最后XML是不是在String str = new String(read, 0, count)里面?
aaaa250 2006-01-23
  • 打赏
  • 举报
回复
谢谢楼上,你写的是MSDN的例子,我也看了,不过我还需要些具体的实现方法啊。
比如说,我要发的请求是 http://www.163.com?id=1 怎么发送
服务器给我发的是 http://10.0.0.38:9090/RetailShop/RetailShopServlet -这是一个XML
我接收然后得到XML,怎么接受啊?
真相重于对错 2006-01-23
  • 打赏
  • 举报
回复
获得xml
可以通过
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
Console.WriteLine("\r\nResponse stream received.");
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
Console.WriteLine("HTML...\r\n");
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String(read, 0, count);
Console.Write(str);
count = readStream.Read(read, 0, 256);
}
Console.WriteLine("");
// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close();

真相重于对错 2006-01-23
  • 打赏
  • 举报
回复
HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
HttpWReq.KeepAlive = false;
HttpWReq.Headers.Add("Accept-Language:da");//加请求头
也可以这样
HttpWReq.Headers.Add("Accept-Language","da");

HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
String ver = HttpWResp.ProtocolVersion.ToString();
HttpWResp.Close();
aaaa250 2006-01-23
  • 打赏
  • 举报
回复
谢谢各位,现在最大的问题是怎么发送HTTP请求与接收HTTP得到XML数据
lidong6 2006-01-23
  • 打赏
  • 举报
回复
把XML转换为DataTable或dataset然后赋给datagrid控件就可以了.

如果XML符合格式的话可以直接转换为dataset
如果不符合格式可以使用XMLDocument进行分析并转换.
aaaa250 2006-01-23
  • 打赏
  • 举报
回复
JAVA的工作不用我负责的,我只是给服务器发送一个HTTP,然后接受一个XML形式的HTTP,之后处理XML就行了,这怎么实现那??
真相重于对错 2006-01-23
  • 打赏
  • 举报
回复
还有这个
ms-help://MS.MSDNQTR.2003FEB.2052/cpqstart/html/cpsmpnetsamples-howtoxmldata.htm#cpsmpLoadDataSetXMLDataSample
如何把xml转为dataset
真相重于对错 2006-01-23
  • 打赏
  • 举报
回复
java serverlet 不懂,不好给你写代码
看看这个
ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconhttp.htm
yf1025 2006-01-23
  • 打赏
  • 举报
回复
关注一下

110,534

社区成员

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

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

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