从服务器端把xml字符串post到另一个页面
来源:互联网 发布:淘宝广场舞套装 编辑:程序博客网 时间:2024/06/03 16:58
public static string PostXml(string url, string xml) { WebRequest request = null; HttpWebResponse response = null; string result = string.Empty; try { request = WebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; StreamWriter writer = new StreamWriter(request.GetRequestStream()); writer.WriteLine(xml); writer.Close(); response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream objStream = response.GetResponseStream(); Byte[] buffer = new Byte[255]; int bytesRead = objStream.Read(buffer, 0, 255); if (bytesRead > 0) { result = Encoding.UTF8.GetString(buffer).Replace("\0", string.Empty); } } } catch (WebException) { } catch (Exception) { } finally { if (request != null) request.GetRequestStream().Close(); if (response != null) response.GetResponseStream().Close(); } return result; }
其中,参数1是要post过去接收xml的页面地址。参数2是xml,因为比较小用了字符串形式的。
返回值result是post过去后的返回值。
另一个页面接收post过来的值。
Page.Response.ContentType = "text/xml"; StreamReader reader = new StreamReader(Page.Request.InputStream); XmlDocument doc = new XmlDocument(); doc.Load(reader); XmlNode node = doc.SelectNodes("root/class")[0]; id = Int(node.SelectSingleNode("Id").InnerText); if (save succesefully) { int id = ; if (id > 0) Response.Write("success"); else Response.Write("fail"); Response.End(); }
- 从服务器端把xml字符串post到另一个页面
- 如同asp那样从html页面post数据到另一个页面asp.net
- 从一个页面跳转到另一个页面
- 用js把数据从一个页面传到另一个页面
- 利用JS脚本把另一个页面加载到当前页面
- 把一个字符串插到另一个字符串的指定位置
- 从Web页面把SQL导出Excel,如何既保存在服务器端,又能自动导出到客户端。
- 从Web页面把SQL导出Excel,如何既保存在服务器端,又能自动导出到客户端。
- 字符串从一个字符串截取到另一个字符串
- 把数据从一个form传递到另一个from
- mysql 把数据库从一个服务器复制到另一个服务器
- 昨天写了一段代码,关于ajax的,一直没有取到从另一个页面response出来的XML值。
- android如何从一个应用跳转到另一个页面
- 从tabbar控制器跳到另一个tabbar控制器页面
- 从一个APP跳转到另一个APP的指定页面
- 跳转到另一个页面
- C#程序如何把窗体文件从从一个项目中复制到另一个项目
- 两个JSP页面,从①页面经过STRUTS跳转到另一个②JSP页面
- svn忽略maven的配置
- 万能的makefile
- 详细解读PHP弹出对话框技巧
- Paths
- 查找所字符串中开始字符和结束字符之间的所有字符
- 从服务器端把xml字符串post到另一个页面
- 程序员最该看的30本书---------------------------国外编辑推荐
- java indexOf方法
- RoR运行、开发环境的安装和配置
- 正则表达式
- opencv CmakeLists.txt 小示例
- hdu 1421 搬寝室 (DP)
- spring的springMVC的一个简单的例子
- linux虚拟机创建共享磁盘