/// <summary>
/// HTTP Get请求
/// </summary>
/// <param name="url"></param>
/// <param name="param"></param>
/// <param name="encode"></param>
/// <returns></returns>
public static string GetData(string url, Encoding encode)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/html;charset=gb2312";
var response = (HttpWebResponse)request.GetResponse();
var rs = response.GetResponseStream();
var sr = new StreamReader(rs, encode);
var result = sr.ReadToEnd();
sr.Close();
rs.Close();
return result;
}
/// <summary>
/// HTTP POST请求
/// </summary>
/// <param name="url"></param>
/// <param name="param"></param>
/// <param name="encode"></param>
/// <returns></returns>
public static string PostData(string url, string parm)
{
byte[] data = new ASCIIEncoding().GetBytes(parm);
// 发送请求
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
// 获得回复
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string result = reader.ReadToEnd();
reader.Close();
return result;
}