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

x
?
Solved

HTTP Post to external website form

Posted on 2008-10-08
8
Medium Priority
?
2,223 Views
Last Modified: 2009-07-29
Hi

I am busy doing investigation into HTTP Posts to other websites. I found the code below which is used for posting HTTP Data to another website form.

My question is simply:
Does this process actually trigger a Form Submit action on the external website??

Thanks
(Please note the code is just a copy from another post simply to indicate what is happening and has not been tested - the question is more theoretical)
///////////////////////////////////////////////////////////////////////////////////////////
ASCIIEncoding encoding =new ASCIIEncoding();
 
string postData  ="p1=" + "FP98";
postData +="p2="  + ordertime;
postData +="p3="  + "Shop";
 
 
byte[]  data = encoding.GetBytes(postData);
 
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://www.aaa.com/vvonline/ccform.asp");
myRequest.Method      = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();

Open in new window

0
Comment
Question by:djcheeky
[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
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:schalcraft
ID: 22668100
In theory, yes, submitting forms to a remote site does work. However, if the remote site doesnt want to allow this, then they wil have taken steps to ensure it cant be done.
0
 

Author Comment

by:djcheeky
ID: 22668130
Thanks - but what I'm asking is will the code above actually trigger a Form submit action with the data provided on the remote site?
0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22668229
You mean like the javascript onSubmit event?
No it doesn't get fired.

Kind regards,

Matthias Vance
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:djcheeky
ID: 22668287
Hi again, Let me elaborate:

The code above creates an HTTP FORM request and sends it to a remote website.

What I would like to know is whether this request that is passed via the code below is the same as someone submitting a form with the same data on the remote website?

Thanks


newStream.Write(data,0,data.Length);

Open in new window

0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22668801
No it's not the same. You are only posting the data that you specify in your program. A form on a website might contain hidden fields etc.

Kind regards,

Matthias Vance
0
 

Author Comment

by:djcheeky
ID: 22668923
Yes, but if the form on the remote site is expeecting form items:
* name
* surname
* age

And I run the code executed below, passing the name,surname and age via the HTTP post request, does that yield the same result as if I had typed in those value into the HTTP form on the remote site and submitted?

Please read what I have written and try to understand it.
Thanks
string postData  ="name=John";
postData +="surname=Smith";
postData +="age=30";
 
 
byte[]  data = encoding.GetBytes(postData);
 
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://www.aaa.com/vvonline/ccform.asp");
myRequest.Method      = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();

Open in new window

0
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 150 total points
ID: 22669320
Yes, it would do exactly the same.
However, you need to change your code in order for it to work correctly.

Kind regards,

Matthias Vance
' Wrong code
string postData  ="name=John";
postData +="surname=Smith";
postData +="age=30";
 
' Right code
string postData = "name=John";
postData += "&surname=Smith";
postData += "&age=30";

Open in new window

0
 

Author Comment

by:djcheeky
ID: 22676094
Aah - ok thanks - Yeah - I grabbed the code from somewhere else and I suspected it may not be perfect :)
Just wanted to know whether they yield the same effect, which they do, so thanks :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
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.…
Suggested Courses

649 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