public void Login()
{
SendRequest("wzq806341010", "wzq123123", "http://www.oukkk.com/user.php");
}
void SendRequest(string username, string password, string path)
{
//拼接提交数据的格式
string s = "username=" + username + "&password=" + password;
//转换为字节数组
byte[] bytesRequestData = Encoding.UTF8.GetBytes(s);
//path不是登录界面,是登录界面向服务器提交数据的界面
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(path);
myReq.Method = "post";
myReq.ContentType = "application/x-www-form-urlencoded";
//填充POST数据
myReq.ContentLength = bytesRequestData.Length;
Stream requestStream = myReq.GetRequestStream();
requestStream.Write(bytesRequestData, 0, bytesRequestData.Length);
requestStream.Close();
//发送POST数据请求服务器
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
//获取服务器返回信息
Stream myStream = HttpWResp.GetResponseStream();
StreamReader reader = new StreamReader(myStream, Encoding.UTF8);
string content = reader.ReadToEnd();
}
用了6楼的方法,没有用,仍然返回的是登录页面,,哪里错了呢,,求解