像C#一样在网页上发送POST请求吗?

Ver*_*cas 1 c# httpwebrequest

可能重复:
如何在C#中模拟浏览器HTTP POST请求并捕获结果

我的网页上有以下表格......

<input type="text" tabindex="1" id="username" name="username" size="30"/>
<input type="password" tabindex="2" id="password" name="password" size="30"/>
Run Code Online (Sandbox Code Playgroud)

我使用这些登录我的网站.
但我想在我的应用程序中提供此功能.
如何使用HTTP Web请求将用户和密码发送到我的验证页面?

The*_*ask 8

尝试使用该WebClient课程.例:

var url = @"..."; 
var nvc = new System.Collections.Specialized.NameValueCollection();
nvc.Add("username", "username");
nvc.Add("password", "password");
var client = new System.Net.WebClient();
var data = client.UploadValues(url, nvc);
var res = System.Text.Encoding.ASCII.GetString(data);
Console.WriteLine(res);
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)