是否可以使用控制台应用程序填写并提交表单?让我们说http://mysite/connection.php网站有以下代码:
<form method="post" action="connection.php">
<input placeholder="User Name" type="text" name="username" id="username" value="" />
<input placeholder="Password" type="password" name="password" id="password" />
<input type="submit" value="Connection" />
</form>
如何使用C#/ VB.NET使用控制台应用程序提交此表单?
答案 0 :(得分:1)
您可以使用WebRequest
在.NET中发布数据
您的代码将是这样的
WebRequest myReq = WebRequest.Create('http://mysite/connection.php');
myReq.Method = "POST";
myReq.ContentLength = data.Length;
myReq.ContentType = "application/json; charset=UTF-8";
/* And your further code goes here */
答案 1 :(得分:1)
您可以按如下方式使用WebClient:
WebClient wc = new WebClient();
NameValueCollection nvc = new NameValueCollection();
nvc.Add("username", username);
nvc.Add("password", pwd);
byte[] responseArray = wc.UploadValues(url,"POST",nvc);
更多细节可在以下网址找到:https://msdn.microsoft.com/en-us/library/900ted1f.aspx