4
나는 양식, 입력 및 벙어리 버튼이있는 내 html-php 웹 페이지가 있습니다. html 요청을 통해 일부 입력란을 채우고 버튼을 누르려 고 시도했지만 불가능합니다.HttpWebRequest 가상 버튼 클릭
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 파일 : 내 사이트
그래서에
<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;
?>
Here 링크입니다 request.php 여기 는 C# 코드입니다 , 어떻게이 버튼을 누를 수 있습니까?
너는하지 마라! response.php에 데이터를 게시하기 만하면됩니다. 클라이언트가 수행하는 작업을 에뮬레이션해야합니다. 버튼을 클릭하면 서버에 데이터가 게시됩니다. Fiddler와 같은 도구를 사용하여 요청의 모양을 확인하십시오. 일단 당신이 알고 있으면 당신은 이미 가지고있는 C# 코드가 좋다. – dash
흠, 고마워, 나는 그것을 시험해보고 싶어! –