通过http请求传递xml流和接收xml流的代码示例 通过http请求传递xml流和接收xml流的代码示例 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string sampleRequest = @"<?xml version=""1.0""?>你的节点";this.Response = ReceiveData(sampleRequest, Server); // Load Xml into a XmlDocument object XmlDocument XmlResponse = new XmlDocument(); try { XmlResponse .LoadXml(this.Response); } catch { }private string ReceiveData(string req, string Server) { ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(req); // Request HttpWebRequest r = (HttpWebRequest)WebRequest.Create(Server); r.Method = "POST"; r.ContentType = "application/x-www-form-urlencoded"; r.ContentLength = data.Length; Stream requestStream = r.GetRequestStream(); r.Write(data, 0, data.Length); r.Close(); WebResponse myResponse = null; string response; try { myResponse = r.GetResponse(); using (StreamReader sr = new StreamReader(myResponse .GetResponseStream())) { response = sr.ReadToEnd(); sr.Close(); } } catch (Exception exc) { response = exc.ToString(); } return response; } string xmlFileName = Server.MapPath("new2.xml"); HttpWebRequest req = null; //设置要POST到的页面URL string url = "http://www.XX.com/Receive2.aspx"; //创建一个HttpWebRequest对象 req = (HttpWebRequest)HttpWebRequest.Create(url); //设置它提交数据的方式post req.Method = "POST"; //设置 Content-type HTTP 标头的值 req.ContentType = "application/x-www-form-urlencoded";// "application/x-www-form-urlencoded;charset=gb2312"; using (StreamWriter requestWriter = new StreamWriter(req.GetRequestStream())) { //定义一个StreamReader对象,用于读取xml文件的内容 StreamReader reader = new StreamReader(xmlFileName); string ret = reader.ReadToEnd(); reader.Close(); requestWriter.WriteLine(ret);//将读取的内容写入到RequestStream中。 }备注 为什么不对呢 http://www.XX.com/Receive2.aspx这个地址都没有接收到任何东西 关于 SQL语句的拼串问题 vs2008自带的水晶报表程序可以实现转换成图片的功能吗? 请问关于EXT框架的问题望指教. 怎样把数据添加到购物车中?谢谢! 发邮件问题 ??? 百分求DataGrid的一些代码,分不够在加... asp.net如何连接oracle数据库? 后退刷新的问题?? datalist中的textbox如何做到焦点离开引发事件?(还是100分) 散分50 C# for循环重复数据问题 我怎么获取子repater里面控件的所有值
string sampleRequest = @"
<?xml version=""1.0""?>
你的节点
";
this.Response = ReceiveData(sampleRequest, Server); // Load Xml into a XmlDocument object
XmlDocument XmlResponse = new XmlDocument();
try
{
XmlResponse .LoadXml(this.Response);
}
catch
{
}private string ReceiveData(string req, string Server)
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(req); // Request
HttpWebRequest r = (HttpWebRequest)WebRequest.Create(Server);
r.Method = "POST";
r.ContentType = "application/x-www-form-urlencoded";
r.ContentLength = data.Length;
Stream requestStream = r.GetRequestStream();
r.Write(data, 0, data.Length);
r.Close();
WebResponse myResponse = null;
string response;
try
{
myResponse = r.GetResponse();
using (StreamReader sr = new StreamReader(myResponse .GetResponseStream()))
{
response = sr.ReadToEnd();
sr.Close();
}
}
catch (Exception exc)
{
response = exc.ToString();
} return response;
}
HttpWebRequest req = null;
//设置要POST到的页面URL
string url = "http://www.XX.com/Receive2.aspx";
//创建一个HttpWebRequest对象
req = (HttpWebRequest)HttpWebRequest.Create(url);
//设置它提交数据的方式post
req.Method = "POST";
//设置 Content-type HTTP 标头的值
req.ContentType = "application/x-www-form-urlencoded";// "application/x-www-form-urlencoded;charset=gb2312";
using (StreamWriter requestWriter = new StreamWriter(req.GetRequestStream()))
{
//定义一个StreamReader对象,用于读取xml文件的内容
StreamReader reader = new StreamReader(xmlFileName);
string ret = reader.ReadToEnd();
reader.Close();
requestWriter.WriteLine(ret);//将读取的内容写入到RequestStream中。
}
备注 为什么不对呢 http://www.XX.com/Receive2.aspx这个地址都没有接收到任何东西