btruby
asked on
trying to use WebRequest / WebClient to fill a form over the web consisting of multiple clicks
Hi all,
I've been having a little problem with the WebClient class, and am hoping someone can help.
Here is what I'm currently working with:
string uri = "www.exampleURL.com";
byte[] postBytes = Encoding.ASCII.GetBytes(po stString_B egin);
byte[] postBytes2 = Encoding.ASCII.GetBytes(po stString2) ;
WebClient myClient = new WebClient();
myClient.Headers.Add("Cont ent-Type", "application/x-www-form-ur lencoded") ;
byte[] response = myClient.UploadData(uri, postBytes);
string myresponse = Encoding.ASCII.GetString(r esponse);
response = myClient.UploadData(uri2, postBytes2);
Here is where I hit my wall.
After I upload the first queryString, the next step in the process is returned.
The URL does not change, but when I go to post the next section of values, it posts them back to the first page/form part.
So, basically I'm filling a form on my website, and then taking the values and using these to complete a form on another site, then parsing the result and using what is relevant. The form on the other site is all on the same page, but goes through roughly 4 button clicks, or Posts. When I try and run the second, it posts to the first. I've looked through the WebRequests and WebClient classes, but haven't seen how to keep everything in sequence.
Can anyone point me to How I can post my second querystring to the returned page from the first request?
Thanks
I've been having a little problem with the WebClient class, and am hoping someone can help.
Here is what I'm currently working with:
string uri = "www.exampleURL.com";
byte[] postBytes = Encoding.ASCII.GetBytes(po
byte[] postBytes2 = Encoding.ASCII.GetBytes(po
WebClient myClient = new WebClient();
myClient.Headers.Add("Cont
byte[] response = myClient.UploadData(uri, postBytes);
string myresponse = Encoding.ASCII.GetString(r
response = myClient.UploadData(uri2, postBytes2);
Here is where I hit my wall.
After I upload the first queryString, the next step in the process is returned.
The URL does not change, but when I go to post the next section of values, it posts them back to the first page/form part.
So, basically I'm filling a form on my website, and then taking the values and using these to complete a form on another site, then parsing the result and using what is relevant. The form on the other site is all on the same page, but goes through roughly 4 button clicks, or Posts. When I try and run the second, it posts to the first. I've looked through the WebRequests and WebClient classes, but haven't seen how to keep everything in sequence.
Can anyone point me to How I can post my second querystring to the returned page from the first request?
Thanks
ASKER
yes, the uri2 is supposed to be just uri in this case.
It is still just posting to the first step, and not continuing on ...
any ideas
It is still just posting to the first step, and not continuing on ...
any ideas
>>So, basically I'm filling a form on my website, and then taking the values and using these to complete a form on another site
What do you mean by "another site"? I don't see any other URL in you code.
The code you provided post twice to the same page. Maybe you are missing something?
What do you mean by "another site"? I don't see any other URL in you code.
The code you provided post twice to the same page. Maybe you are missing something?
ASKER
Here's the code as is (a little stripped down)
postString_Begin = "HomeCountry=USA&MemberTyp e=P&DistID =&CurrPage =Applicati onType&Nex tPage=Appl icationFor m&NextButt on=Continu e";
string postString2 = "EnrollerID=170138&Applica ntTaxID=&A pplicantNa tiveName=& ApplicantF irstname=T est&Applic antMidInit ial=T&Appl icantLastn ame=Tester man&BirthM onth=&Birt hDay=&Birt hYear=&CoN ativeName= &CoFirstna me=&CoMidI nitial=&Co Lastname=& CompanyNam e=&MailAdd ress1=2701 +Dallas+Pk wy&MailAdd ress2=Suit e+330&Mail City=Plano &MailState =TX&MailPo stalCode=7 5093&MailC ityLimits= I&ShipAddr ess1=2701+ N.+Dallas+ Pkwy&ShipA ddress2=Su ite+100&Sh ipCity=Pla no&ShipSta te=TX&Ship PostalCode =75093&Shi pCityLimit s=I&NightP hone=11122 23434&DayP hone=11122 23535&Cell Phone=2225 556767&Fax =333456787 8&Email=me tman71@hot mail.com&C orporateMa il=Y&Broad castMail=Y &IAgree=on &VOIAgree= Y&Product_ 1=GXL&Prod uctQty_1=1 &Product_2 =MAXWLXSYS TEM&Produc tQty_2=0&P roduct_3=M AXWLX&Prod uctQty_3=0 &Product_4 =MAXNFUZE& ProductQty _4=0&Produ ct_5=GXLVC &ProductQt y_5=0&Ship Via=3&ASPr oduct_1=GX L&ASProduc tQty_1=1&A SProduct_2 =MAXWLX&AS ProductQty _2=0&ASPro duct_3=MAX NFUZE&ASPr oductQty_3 =0&ASProdu ct_4=GXLVC &ASProduct Qty_4=0&AS Day=25&ASS tartDate=2 0090426&AS ShipVia=3& CurrPage=A pplication Form&NextP age=Applic ationPayme nt&NextBut ton=Contin ue";
string uri = "https://nettrax.myvoffice.com/maxintl/Application/Apply.cfm?EnrollerId=170138";
byte[] postBytes = Encoding.ASCII.GetBytes(po stString_B egin);
byte[] postBytes2 = Encoding.ASCII.GetBytes(po stString2) ;
WebClient myClient = new WebClient();
myClient.Headers.Add("Cont ent-Type", "application/x-www-form-ur lencoded") ;
byte[] response = myClient.UploadData(uri, postBytes);
string myresponse = Encoding.ASCII.GetString(r esponse);
response = myClient.UploadData(uri, postBytes2);
as you can see, postString_Begin submits input for the first step, and then postString2 has simulated values for the second step in the form.
Basically, I'm filling out this order form on my site, so I can redesign the cart, and then taking the input and passing it through to the other webserver. I've got everything in place, except I can't seem to get to post to the second step. All through out, the url doesn't change, excpet the parameter falls off after the first step.
postString_Begin = "HomeCountry=USA&MemberTyp
string postString2 = "EnrollerID=170138&Applica
string uri = "https://nettrax.myvoffice.com/maxintl/Application/Apply.cfm?EnrollerId=170138";
byte[] postBytes = Encoding.ASCII.GetBytes(po
byte[] postBytes2 = Encoding.ASCII.GetBytes(po
WebClient myClient = new WebClient();
myClient.Headers.Add("Cont
byte[] response = myClient.UploadData(uri, postBytes);
string myresponse = Encoding.ASCII.GetString(r
response = myClient.UploadData(uri, postBytes2);
as you can see, postString_Begin submits input for the first step, and then postString2 has simulated values for the second step in the form.
Basically, I'm filling out this order form on my site, so I can redesign the cart, and then taking the input and passing it through to the other webserver. I've got everything in place, except I can't seem to get to post to the second step. All through out, the url doesn't change, excpet the parameter falls off after the first step.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Rimvis,
WebRequest is working as needed once I got the cookies handled.
WebRequest is working as needed once I got the cookies handled.
>> response = myClient.UploadData(uri2, postBytes2);
uri2? Isn't it a typo?
Regards,
Rimvis