C# Http POST get
using System.IO;
using System.Net;
/// <summary>
/// HttpWebRequest发送Post请求
/// </summary>
/// <param name="postUrl"></param>
/// <param name="paramData"></param>
/// <param name="dataEncode"></param>
/// <returns></returns>
public static string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
{
string ret = string.Empty;
byte[] byteArray = dataEncode.GetBytes(paramData);
//转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), dataEncode);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
return ret; }
/// <summary>
/// WebClient发送Get请求,编码UTF8
/// </summary>
/// <param name="Url"></param>
/// <returns></returns>
public static string Get(string Url) {
string result = "";
HttpWebRequest httpReq;
httpReq = (HttpWebRequest)WebRequest.Create(new Uri(Url));
WebResponse wr = httpReq.GetResponse();
Stream responseStream = wr.GetResponseStream();
StreamReader respStreamReader = new StreamReader(responseStream);
result = respStreamReader.ReadToEnd();
responseStream.Dispose(); wr.Dispose();
return result;
}
随机推荐
- Tomcat配置gzip压缩
HTTP 压缩能够大大提高浏览站点的速度,它的原理是,在client请求网 页后,从server端将网页文件压缩,再下载到client,由client的浏览器负责解 压缩并浏览.相对于普通的浏览过程H ...
- Qss All
/* * OOMidi application style sheet */QFrame#transportToolButtons{border: 0;spacing: 0;margin: 0;pad ...
- JAAS LOGIN IN WEBLOGIC SERVER--reference
The Java Authentication and Authorization Service (JAAS) is a standard extension to the security in ...
- System Operations on AWS - Lab 6W - Using Auto Scaling (Windows)
创建你的一个web server,然后将这个实例制成你的AMI,通过启动配置生成一个Auto Scaling组(包括scale-in/scale-out策略),配置一台Load Balancer指向你 ...
- springmvc获得项目根目录(绝对路径)
原文:http://www.bubuko.com/infodetail-790547.html 在项目中有时候我们需要记录日志或者上传图片,需要知道项目的具体路径,如果项目中使用了spring,那么获 ...
- Weex命令
1.下载安装 $ git clone https://github.com/alibaba/weex.git //通过brew安装node $ brew install node //通过node安装 ...
- ASP.NET程序如何更新发布
ASP.NET程序如何更新发布 一.首先右键项目,点击“发布” 然后,新建名称.类型选择文件,然后点击下一步: 点击发布即可! 二.
- Android增加监听的三种实现方式
在Android中,为一个按钮增加监听的方式有五种 1.匿名内部类 @Override protected void onCreate(Bundle savedInstanceState) { sup ...
- CI 笔记7,easyui 异步加载
在做后台导航时,需要异步加载,pid和id的循环问题,在controller中,建立另外一个方法,嵌套循环,查找是否pid〉1. public function nav_list() { $this- ...
- 【转】发布iOS应用程序到苹果APP STORE完整流程
原文: http://www.cnblogs.com/JuneWang/p/3850859.html 可以为每个app上传5张截图,虽然至少需要上传一张,可能很少有人会只上传一张图片.另外,你还需要分 ...