ASP.NET中Request.InputStream使用
2014-04-02 10:02
316 查看
将数据作为XML数据发送,例如:
接收端通过Request.InputStream读取:
byte[] byts = new byte[Request.InputStream.Length];
Request.InputStream.Read(byts,0,byts.Length);
string req = System.Text.Encoding.Default.GetString(byts);
req = Server.UrlDecode(req);
对于完整的XML数据,可以:
public void PostXml(string url, string xml) { byte[] bytes = Encoding.UTF8.GetBytes(xml); HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.Method = "POST"; request.ContentLength = bytes.Length; request.ContentType = "text/xml"; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); } HttpWebResponse response = (HttpWebResponse) request.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); } }
接收端通过Request.InputStream读取:
byte[] byts = new byte[Request.InputStream.Length];
Request.InputStream.Read(byts,0,byts.Length);
string req = System.Text.Encoding.Default.GetString(byts);
req = Server.UrlDecode(req);
对于完整的XML数据,可以:
xmlDoc = new XmlDocument(); xmlDoc.load(Request.InputStream);
相关文章推荐
- 转]ASP.NET生成XML的一些方法
- Asp.net MVC的Model Binder工作流程以及扩展方法(3) - DefaultModelBinder
- Asp.Net Forms 身份验证
- Asp.Net MVC3.0项目部署到Win7 64过程总结
- ASP.NET Web API 全局权限和全局异常处理
- ASP.NET MVC获取上传的路径
- ASP.NET—009:前台传值的另一种方式$.post
- [ASP.NET] GridView 依條件更改某列背景顏色
- Aspect 切点表达式(xml形式,非注解形式的)
- [ASP.NET] 如果将缓存“滑动过期时间”设置为1秒会怎样?
- ASP.Net页面上用户控件相互调用的方法
- ASP.NET Web API 中的异常处理(转载)
- ASP.NET 使用List<T>.Remove 不生效
- dojo/on和dojo/aspect的简单区分
- ASP.NET登录验证码
- Asp.net MVC中的ViewData与ViewBag
- 在ASP 调用 VB.net 编写的dll 出错 提示:Microsoft VBScript 运行时错误 错误 '800a01ad' ActiveX 部件不能创建对象
- Asp.net MVC文章搜集索引
- ASP.NET Web API 2 中的属性路由使用(转载)
- 《ASP.NET MVC4 WEB编程》学习笔记------Web API