1.HttpWebRequest+HttpWebResponse用于登录,然后转到页面“ex.asps”
2.发送HttpWebRequest(带有ddl中的select选项)+HttpWebRespons以保存我需要的所有信息到StreamReader。
1.我成功了,我看到了所有的信息
2.我看到了dll(Id,所有选项,值,名称),但我找不到选择正确选项的方法,我只能看到并保存第一个选项,所以我需要逐个选择所有ddl并保存数据。
例如:像4个用户的ddl,每个用户都有自己的数据,如(年龄、ID…)
我只能保存一个用户,但我需要更改ddl以获取新数据
这是我的代码
if (IsLogin)
{
HttpWebResponse RedirectResponse = RedirectToUrl("https://services.test.com/Pages/Trans.aspx");
Stream streamResponse = RedirectResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
outString = streamRead.ReadToEnd();
System.Collections.ArrayList strAccountList = GetListByID("ctl00_PlaceHolderMain_AccountsDDL_ddlAccounts");
for (int intAccountCount = 0; intAccountCount < strAccountList.Count; intAccountCount++)
{
string[] strAcctList = strAccountList[intAccountCount].ToString().Split('\t');
string strAccountNumber = strAcctList[0];
PostString += "__EVENTVALIDATION=" + GetValueByID(LoginInfo, "__EVENTVALIDATION") + "&";
PostString += "ctl00$PlaceHolderMain$AccountsDDL$ddlAccounts=" + strAccountNumber + "&";
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create("https://services.test.com/currentaccount/Pages/current.aspx");
postRequest.CookieContainer = new CookieContainer();
postRequest.CookieContainer = _cookies;
postRequest.Method = WebRequestMethods.Http.Post;
postRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
postRequest.AllowWriteStreamBuffering = false;
postRequest.ProtocolVersion = HttpVersion.Version11;
postRequest.AllowAutoRedirect = false;
postRequest.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.ASCII.GetBytes(PostString);
postRequest.ContentLength = byteArray.Length;
Stream newStream = postRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse postResponse = (HttpWebResponse)postRequest.GetResponse();
outString = "";
Stream streamResponseLoginForm = postResponse.GetResponseStream();
StreamReader streamReadLoginForm = new StreamReader(streamResponseLoginForm);
outString = streamReadLoginForm.ReadToEnd();
if (outString == null)
{
LogOut();
}
}