我正在尝试构建c#应用程序,它会在站点中出现“更新”时通知我。 站点登录表单包含3个文本框,它是login.aspx。
我的问题是,如何将3个详细信息“发送”到网站并从我想要在c#中构建的应用程序连接(验证),如果可能,我该怎么办? 我寻找任何指南或其他东西,但没有找到。
答案 0 :(得分:0)
您需要使用WebClient
课程。有关此课程的更多信息,请访问http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx
答案 1 :(得分:0)
First you need post a form using c#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);
// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
then try to save cookie, its required to store aspnet_session_id into client for future requests
private class CookieAwareWebClient : WebClient
{
public CookieAwareWebClient()
: this(new CookieContainer())
{ }
public CookieAwareWebClient(CookieContainer c)
{
this.CookieContainer = c;
}
public CookieContainer CookieContainer { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = this.CookieContainer;
}
return request;
}
}
确保您在每个请求上发送和恢复aspnet_session_id。 和宾果游戏!!
我建议你阅读this。