[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-04-01
6
Medium Priority
?
390 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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