方法一、
System.Net.WebClient WebClientObj = new
System.Net.WebClient();
System.Collections.Specialized.NameValueCollection
PostVars = new
System.Collections.Specialized.NameValueCollection();
PostVars.Add("A1","0");//键值对
PostVars.Add("A2","0");
PostVars.Add("A3","000");
try
{
byte[] byRemoteInfo =
WebClientObj.UploadValues("http://www.lovezhao.com/vote.asp","POST",PostVars);
//下面都没用啦,就上面一句话就可以了
string
sRemoteInfo = System.Text.Encoding.Default.GetString(byRemoteInfo); //这里的编码方式可能不一样
//这是获取返回信息
Console.WriteLine(sRemoteInfo );
}
catch
{}
方法二、
CSDN上面的
public static void Test ()
{
WebRequest request = WebRequest.Create("http://soso.music.qq.com/fcgi-bin/fcg_song.fcg");
request.Method = "POST";
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.GetEncoding("gb2312").GetBytes(postData);
//Encoding.UTF8.GetBytes (postData);//你想要的编码方式
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);
dataStream.Close ();
WebResponse response = request.GetResponse ();
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("gb2312"));//这里也要编码.根据你的需要
string responseFromServer = reader.ReadToEnd ();
Console.WriteLine (responseFromServer);
reader.Close ();
dataStream.Close ();
response.Close ();
}
可能得到的会乱码,你要自己去看看原来那个网站上的使用的是上面编码
不太好直接 转载,我就只要 把原文 复制下来了.出处见 http://www.blogjava.net/wangxinsh55/archive/2007/06/22/125847.html