C#post、get发送并且接收数据
2017-01-21 16:52
597 查看
public static string SendQingQiu(string sUrl, string sParam, string method) { string result = ""; HttpWebRequest req = WebRequest.Create(sUrl) as HttpWebRequest; HttpWebResponse res = null; if (req != null) { req.Method = method; req.ContentType = "application/x-www-form-urlencoded"; byte[] postData = Encoding.GetEncoding("UTF-8").GetBytes(sParam); if (postData.Length > 0) { req.ContentLength = postData.Length; req.Timeout = 15000; Stream outputStream = req.GetRequestStream(); outputStream.Write(postData, 0, postData.Length); outputStream.Flush(); outputStream.Close(); try { res = (HttpWebResponse)req.GetResponse(); System.IO.Stream InputStream = res.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("UTF-8"); StreamReader sr = new StreamReader(InputStream, encoding); result = sr.ReadToEnd(); } catch (Exception ex) { } } else { res = (HttpWebResponse)req.GetResponse(); System.IO.Stream InputStream = res.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("UTF-8"); StreamReader sr = new StreamReader(InputStream, encoding); result = sr.ReadToEnd(); sr.Close(); } } return result; }
相关文章推荐
- 微信通过openID发送消息/后台post、get提交并接收数据 C# .NET 配置404,500等错误信息 连接字符串
- C#带cookie Post和Get方式发送数据,保持cookie
- c#发送和接收get,post消息
- C#模拟Post和Get方式发送数据
- PHP中接收send/POST/GET发送的数据
- 前端jQuery向后台发送POST请求并接收后台返回的数据(C#)
- AJAX中使用post,get接收发送数据的区别
- Asp.net XMLHTTP 基类 (GET,Post发送和接收数据)
- c#中 put方式发送Json数据、post方式、delete方式、get方式、
- C#模拟Post和Get方式发送数据的技巧
- C#带cookie Post和Get方式发送数据
- 初涉Ajax,以post或get方法发送数据,以json或xml形式接收服务器返回的请求
- C# winform端 通过HttpWebRequest进行post和get请求,数据格式为json,后台java端接收,其中有关传输特殊字符(\t,\r,',\n,n)等处理
- express 4.x req.query(get方式) req.body(post方式) 接收浏览器发送过来的数据
- C#使用post发送和接收数据的方法
- C#模拟Post和Get方式发送数据 保持COOKIE
- C#模拟Post和Get方式发送数据
- C#带cookie Post和Get方式发送数据,保持cookie
- Asp.net XMLHTTP封装类(GET,Post发送和接收数据)