用類比POST方法向http://localhost:81/clientpost/post.php提交評論資訊
using System.Net;
using System.IO;
private void btnPost_Click(object sender, EventArgs e)
{
WebClient wc = new WebClient();
System.Collections.Specialized.NameValueCollection postvars = new System.Collections.Specialized.NameValueCollection();
postvars.Add("txtcontent", "yangcai");
byte[] byremoteinfo = wc.UploadValues("http://localhost:81/clientpost/post.php", "POST", postvars);
string sremoteinfo = System.Text.Encoding.Default.GetString(byremoteinfo);
MessageBox.Show(sremoteinfo);
}
http://localhost:81/clientpost/post.php 的代碼如下(PHP部分)
$content=$_POST["txtcontent"];
$db=mysql_connect("localhost","root","22829652");
mysql_select_db("clientPost",$db);
mysql_query("INSERT INTO comment (content) VALUES ('".$content."')");
mysql_close($db);
http://localhost:81/clientpost/post.php 的代碼如下(HTML部分)
<form id="form1" name="form1" method="post" action="">
<p>
<textarea name="txtcontent" rows="5" id="txtcontent"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p>
</form>