C#使用Windows应用程序将用户名/密码发布到登录页面

时间:2012-05-26 12:05:17

标签: c# asp.net login http-post

我有2个文本框和1个按钮的登录页面

<input name="txtUserName" type="text" value="666" id="txtUserName" class="textbox">

<input name="txtPassword" type="password" id="txtPassword" class="textbox">

和按钮就是这样

<input type="submit" name="LoginButton" value="Login To WebSite" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;LoginButton&quot;, &quot;&quot;, true, &quot;Login1&quot;, &quot;&quot;, false, false))" id="LoginButton" class="button" style="font-family:tahoma;font-size:10px;">  
  

我没有网页的源代码,只有我要发送的东西   我的用户名和密码和接收是“登录正常或登录是   FAIL“

当用户输入用户名和密码并单击“登录到网站”按钮时,如果用户/通过正确的用户登录到显示用户面板的页面http://example.com/Default.aspx,如果登录失败,系统再次显示login.aspx
现在我设计的Windows应用程序有2个文本框和一个按钮
我想当我点击按钮textbox1和textbox2文本作为登录信息发送到网站,如果这个数据是正确的,请告诉我登录成功的消息,否则显示错误

1 个答案:

答案 0 :(得分:0)

当您在ASP.Net中按“登录到网站”按钮时,它会调用javascript WebForm_DoPostBackWithOptions函数。

根据this MSDN Magazine's article,此函数对所选页面执行POST操作。

要在Windows应用程序中执行此操作,您可以使用WebClient class(请参阅MSDN页面底部的示例代码)或HttpWebRequestHttpWebResponse的组合。

如何使用HttpWebRequest和HttpWebResponse is described in this codeproject article

Note that I based my answer on this other SO answer