$("#ctl00_PlaceHolderMain_AccountsDDL_ddlAccounts")[0].selectedIndex = 0;//Here we select the index
__doPostBack('ctl00_PlaceHolderMain_AccountsDDL_ddlAccounts','') // here the postback
How to select from DropDownList in HttpWebRequest
-
28-06-2023 - |
Question
1.HttpWebRequest+HttpWebResponse for login then go to page "ex.asps" 2.send HttpWebRequest(with select option from ddl)+HttpWebRespons to save all info that i need to StreamReader.
1.I succeed i see all info all work 2.I see the dll(Id, all options,values,name) But i cant find out the way to select the right option i can see and save only first one,nut i need to go trow the all ddl select one by one and save the data. Ex: Like ddl with 4 User and each one have they own data like (Age,ID...) i can save only 1 user but i need to change ddl to get new data
This is my code
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();//Here i can see that data is not changed
if (outString == null)
{
LogOut();
}
}
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow