Solved

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

Posted on 2009-04-01
6
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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