我有我的HTML,PHP网页与形式,投入,并请提交按钮。 随着HTML请求I \中号试图填补某些领域,按下一个按钮,但我不能。 下面是C#代码:
public static string PostData(string data)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/request.php"); //http://businesslist.com/search/clients/?m=userspace&d=addclassified
request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
byte[] EncodedPostParams = Encoding.UTF8.GetBytes(data);
request.ContentLength = EncodedPostParams.Length;
request.GetRequestStream().Write(EncodedPostParams, 0, EncodedPostParams.Length);
request.GetRequestStream().Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string str = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
return str;
}
static void Main(string[] args)
{
string data = PostData("name=" + HttpUtility.UrlEncode("lol") + "&btn=Clicked");
Console.WriteLine(data);
Console.ReadLine();
}
2个PHP文件:request.php
<html>
<head>
<title>HTTP Request</title>
</head>
<body>
<form action ="http://localhost/response.php" method ="POST">
<input type="text" name="name">
<input type="password" name="pass">
<select name="country">
<option value="-1" selected="selected">Select State/Country</option>
<option value="82">Select 1</option>
<option value="83">Select 2</option>
</select>
<input type="submit" name="btn">
</form>
</body>
</html>
response.php
<?php
$data = $_POST["name"];
echo $data;
?>
这里是链接到我的网站
所以,我怎么能按这个按钮?