日期:2014-05-17 浏览次数:20476 次
/// <summary>
/// Post数据
/// </summary>
private static bool HttpPost(string sUrl, string data, ref string sError)
{
string postData = data;
try
{
if (string.IsNullOrEmpty("sUrl")) throw new Exception("URL地址有误");
//将数据提交到代理
WebRequest myWebRequest = WebRequest.Create(sUrl);
myWebRequest.Method = "POST";
myWebRequest.Timeout = 4000;
myWebRequest.ContentType = "application/x-www-form-urlencoded";
Stream streamReq = myWebRequest.GetRequestStream();
byte[] byteArray = Encoding.GetEncoding("GB2312").GetBytes(postData);
streamReq.Write(byteArray, 0, byteArray.Length);
streamReq.Close();
//获取系统返回的数据
WebResponse myWebResponse = myWebRequest.GetResponse();
StreamReader sr = new StreamReader(myWebResponse.GetResponseStream());
string res = sr.ReadToEnd();
sr.Close();