我想使用WebClient登录网站。 登录表单:
<input id="txtID" name="txtID" type="text" maxlength="20" onfocus="javascript:setUserNameData(this);" onblur="javascript:checkUserNameData(this);" value="Tên Truy Cập" />
<input id="txtPW" name="txtPW" type="text" maxlength="12" onfocus="this.value='';setPWDXXX();" onblur="javascript:checkPWData(this);" oninput="setPWDXXX();" value="Mật Khẩu" />
<input id="hidubmit" name="hidubmit" type="hidden" />
<input id="IEVerison" type="hidden" name="IEVerison" value="0" />
<input type="hidden" id="detecResTime" name="detecResTime" value="" />
<input id="detecas-analysis" type="hidden" name="detecas-analysis" value="{}" />
<input type="hidden" name="hidServerKey" value="bong88.com" />
<input name="tk" type="hidden" id="tk" value="25af27e2101f14442f89c7f1f20f08c951c82c6f5582ae" runat="server" />
<input id="IsSSL" name="IsSSL" type="hidden" />
每次进入网站时都会更改2个值txtCode和__tk。 我试图获取源,获取值然后发送请求到网站但我失败了。 我错了还是错过了什么?
mycode的:
private string GetSourceForMyShowsPage()
{
using (var client = new WebClientEx() )
{
client.Headers.Add("User-Agent: Other");
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
string html = client.DownloadString("https://www.bong88.com/login888.aspx?IsSSL=1");
htmlDoc.LoadHtml(html);
string txtCode = htmlDoc.GetElementbyId("txtCode").GetAttributeValue("value", "");
string tk = htmlDoc.GetElementbyId("__tk").GetAttributeValue("value", "");
var values = new NameValueCollection
{
{ "txtID", "" },
{ "txtPW", "" },
{"txtCode", txtCode },
{ "hidubmit",""},
{ "IEVerison","0" },
{" detecResTime","" },
{ "detecas-analysis", "{}"},
{ "hidServerKey",".com" },
{ "__tk", tk },
{ "IsSSL", "1" },
{ "PF", "Default"},
{ "RMME", "on" },
};
// Authenticate
client.UploadValues("https://www.bong88.com/login888.aspx?IsSSL=1", values);
//Download desired page
return client.DownloadString("https://nvlai.bong88.com/sports");
}
}
public class WebClientEx : WebClient
{
public CookieContainer CookieContainer { get; private set; }
public WebClientEx()
{
CookieContainer = new CookieContainer();
}
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = CookieContainer;
}
return request;
}
}
我认为string html = client.DownloadString("https://www.bong88.com/login888.aspx?IsSSL=1");
和client.UploadValues("https://www.bong88.com/login888.aspx?IsSSL=1", values);
是不同的。所以我失败了