RT,我需要做个demo aa.aspx.cs里面post一个xml格式数据到bb.aspx页面该如何做?
我试了以下代码
string postXml = "<?xml version=\"1.0\" encoding=\"GBK\"?><sync_req><head><id>WXCS</id><pwd>zs@0822*hxyd</pwd></head>" +
"<body><area>0760</area><serviceid>ZSWX</serviceid><appName>SZtest</appName><phoneList><phone><phoneNum></phoneNum>" +
"<action>A</action> <position_type>A</position_type><ue_type>1</ue_type><servicetype>AL</servicetype><status>S</status> <locationTime>1</locationTime>" +
"</phone> </phoneList></body></sync_req>";
string url = "http://localhost:3496/BusRoute.aspx";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = postXml.Length;
Stream newStream = myRequest.GetRequestStream();
byte[] data = Encoding.GetEncoding("GB2312").GetBytes(postXml);
// 发送数据
newStream.Write(data, 0, data.Length);
HttpWebResponse res = myRequest.GetResponse() as HttpWebResponse;
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
String ret = sr.ReadToEnd();
XmlDocument doc = new XmlDocument();
doc.LoadXml(ret);
string mes = doc.GetElementsByTagName("resultInfo")[0].InnerText;
结果在HttpWebResponse res = myRequest.GetResponse() as HttpWebResponse;执行到这句是报
远程服务器返回错误: (500) 内部服务器错误。
代码没有问题,可是url改成“http://120.197.89.32/ELIS/lbsServle”就可以正确返回结果,现在我想在本地程序http://localhost:3496/BusRoute.aspx测试改怎么做?
求高手解决!!!!!