Solved

trying to use WebRequest / WebClient to fill a form over the web consisting of multiple clicks

Posted on 2009-04-01
6
368 Views
Last Modified: 2012-05-06
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(postString_Begin);
byte[] postBytes2 = Encoding.ASCII.GetBytes(postString2);

WebClient myClient = new WebClient();
myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

byte[] response = myClient.UploadData(uri, postBytes);

string myresponse = Encoding.ASCII.GetString(response);

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
 
 
 
0
Comment
Question by:btruby
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 24046688
Hello btruby,

>> response = myClient.UploadData(uri2, postBytes2);

uri2? Isn't it a typo?


Regards,

Rimvis
0
 

Author Comment

by:btruby
ID: 24046775
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
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24046914
>>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?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:btruby
ID: 24047047
Here's the code as is (a little stripped down)

postString_Begin = "HomeCountry=USA&MemberType=P&DistID=&CurrPage=ApplicationType&NextPage=ApplicationForm&NextButton=Continue";
string postString2 = "EnrollerID=170138&ApplicantTaxID=&ApplicantNativeName=&ApplicantFirstname=Test&ApplicantMidInitial=T&ApplicantLastname=Testerman&BirthMonth=&BirthDay=&BirthYear=&CoNativeName=&CoFirstname=&CoMidInitial=&CoLastname=&CompanyName=&MailAddress1=2701+Dallas+Pkwy&MailAddress2=Suite+330&MailCity=Plano&MailState=TX&MailPostalCode=75093&MailCityLimits=I&ShipAddress1=2701+N.+Dallas+Pkwy&ShipAddress2=Suite+100&ShipCity=Plano&ShipState=TX&ShipPostalCode=75093&ShipCityLimits=I&NightPhone=1112223434&DayPhone=1112223535&CellPhone=2225556767&Fax=3334567878&Email=metman71@hotmail.com&CorporateMail=Y&BroadcastMail=Y&IAgree=on&VOIAgree=Y&Product_1=GXL&ProductQty_1=1&Product_2=MAXWLXSYSTEM&ProductQty_2=0&Product_3=MAXWLX&ProductQty_3=0&Product_4=MAXNFUZE&ProductQty_4=0&Product_5=GXLVC&ProductQty_5=0&ShipVia=3&ASProduct_1=GXL&ASProductQty_1=1&ASProduct_2=MAXWLX&ASProductQty_2=0&ASProduct_3=MAXNFUZE&ASProductQty_3=0&ASProduct_4=GXLVC&ASProductQty_4=0&ASDay=25&ASStartDate=20090426&ASShipVia=3&CurrPage=ApplicationForm&NextPage=ApplicationPayment&NextButton=Continue";
string uri = "https://nettrax.myvoffice.com/maxintl/Application/Apply.cfm?EnrollerId=170138";
byte[] postBytes = Encoding.ASCII.GetBytes(postString_Begin);
byte[] postBytes2 = Encoding.ASCII.GetBytes(postString2);
WebClient myClient = new WebClient();
myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] response = myClient.UploadData(uri, postBytes);
string myresponse = Encoding.ASCII.GetString(response);
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.
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 125 total points
ID: 24047413
Try WebRequest:

        string uri = "www.exampleURL.com";
 

        PostData(uri, postString_Begin);

        PostData(uri, postString2);
 
 
 

        string PostData(string uri, string data)

        {

            WebRequest req = WebRequest.Create(uri);

            req.Method = "Post";

            req.ContentType = "application/x-www-form-urlencoded";
 

            Stream s = req.GetRequestStream();
 

            byte[] bytes = Encoding.ASCII.GetBytes(data);

            s.Write(bytes, 0, bytes.Length);

            s.Close();
 

            StreamReader r = new StreamReader(req.GetResponse().GetResponseStream());
 

            return r.ReadToEnd();

        }

Open in new window

0
 

Author Comment

by:btruby
ID: 24051773
Thanks Rimvis,
WebRequest is working as needed once I got the cookies handled.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now