HttpWebRequest Post 方式发送 XML数据
来源:互联网 发布:知其不可奈何安之若命 编辑:程序博客网 时间:2024/05/16 17:01
昨天开发过程中用到 HttpWebRequest 需要用POST方式发送XML数据 因为XML数据中带有<或着?等特殊符号所以需要用URLEcode 方法进行编码 同时接收页面应该关闭设置ValidateRequest="false"关闭对请求数据的验证
public string PostAndGetHTML(string targetURL, string param)
{
//formData用于保存提交的信息
string formData =HttpUtility.UrlEncode(param);
formData = "strXml=" + formData;
//把提交的信息转码(post提交必须转码)
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(formData);
//开始创建请求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetURL);
request.Method = "POST"; //提交方式:post
request.ContentType ="application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);//将请求的信息写入request
newStream.Close();
try
{
//向服务器发送请求
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.GetEncoding("utf-8"));
string strResult = sr.ReadToEnd();
}
catch
{
}
}
- HttpWebRequest Post 方式发送 XML数据
- HttpWebRequest发送Post数据
- HttpWebRequest发送数据 post
- POST方式发送XML数据
- HttpWebRequest GET 方式发送数据
- POST方式发送数据
- post方式发送数据
- .net HttpWebRequest Post xml
- 用httpwebrequest/httpwebresponse向服务器POST发送及接收数据
- 用httpwebrequest/httpwebresponse向服务器POST发送及接收数据
- C# httpwebrequest post 发送的数据 urlencode 问题
- HttpWebRequest Post数据
- HttpWebRequest发送模拟POST请求
- HttpWebRequest Post方式传值
- http post方式发送xml格式消息
- post方式发送和解析xml
- silverlight HttpWebRequest post请求数据
- 关于HttpWebRequest Post数据学习
- ext radiogroup 去掉白色背景色
- CSS3 Border-radius
- 如何抓取AJAX Javascript模拟的超链接
- 关于SIGPIPE导致的程序退出
- html特殊字符
- HttpWebRequest Post 方式发送 XML数据
- ADO.NET 4 快速上手(9)——实体框架(Entity Framework)
- Sybase配置参数(转载)
- 多线程设计
- linux 外部中断例子
- 使用异步 I/O 大大提高应用程序的性能
- dismiss all popup view
- powerdesigner 设置默认值
- 更改并发管理器的并发数