提交(POST):
需要导入命名空间:
using System.Net;
using System.IO;
string postData = "username=" + Login_用户名.Text + "&password=" + Login_密码.Text;//POST参数和值写入POSTDATE里
byte[] byteArray = Encoding.Default.GetBytes(postData);
string url = "http://127.0.0.1/user.php"; //POST到网站
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
接收返回信息:
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.Default);
string Message = php.ReadToEnd();
这里的Message即为网页返回的信息!