模拟发送POST或Get请求
2012-04-12 14:12
363 查看
UTF8Encoding encoding = new UTF8Encoding(); byte[] data = encoding.GetBytes(requestDataXml.ToString()); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.Method = “POST”; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream(); // 发送数据
newStream.Write(data, 0, data.Length); newStream.Close(); // 返回数据 HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); XElement xe = XElement.Parse(content); return xe;
相关文章推荐
- HttpClient模拟get,post请求并发送请求参数(json等)
- C#模拟http 发送post或get请求的简单实例
- Java后台模拟发送http的get和post请求,并测试
- php 模拟浏览器 发送 post 和 get 请求(兼容curl + file_get_contents)
- PHP模拟发送POST请求之四、加强file_get_contents()发送POST请求
- C#模拟http 发送POST或GET请求
- C#模拟http 发送POST或GET请求
- 【实战】(二)android模拟qq登录(apache的httpClient发送get和post请求)
- HttpClient模拟get,post请求并发送请求参数(json等)
- C#模拟http 发送post或get请求
- C#模拟发送http get、post请求的方式
- HttpClient模拟get,post请求并发送请求参数(json等)
- C#模拟http 发送post或get请求
- php模拟发送GET和POST请求
- C#模拟http 发送post或get请求
- curl模拟http发送get或post请求
- 模拟请求 get 、 post、put、delete 发送 xml\json\a=1&b=2&c= 等形式参数,代理设置
- PHP模拟发送POST请求之四、加强file_get_contents()发送POST请求
- HttpClient模拟get,post请求并发送请求参数(json等)
- GET、POST请求处理中文问题(用HttpURLConnection模拟发送请求)