Register  |  Login

Question Details    

   Question

Time: 09:51 - Jul 19, 2006     Asked by: theDude      Status: Answered      Points: 75   

Create a post request programmatically in ASP.NET?

How can i create a post request programmatically in asp.net (C#) without having to actually submit an html-form? Is it possible?

Ask a New Question

Become a Quomon Expert

Current Categories

 

Other Questions Needing Answers


   

Answer Discussion
Answer Discussion
Answer Summaries
Answer Summary
 
Hi,

I am not sure what exactly you want to do. A post request always submits the web form. Do you want to use Ajax style programming where you don't submit the webform but you have a request - response to the web server? Do you use ASP.NET? Java? JavaScript?

In a nutshell?

You use a XMLHttpRequest object in a Java script on your page. You do for example an XMLHttpRequestObject.open("GET", "http://localhost/somewhere/some_data.txt); which returns the content of the text file. This is really just scratching the surface!! There are books about Ajax and the Microsoft adoption ATLAS. I suggest for a start to get the book "Ajax for Dummies" (Yes, experts are allowed to read Dummie books, too) by Steve Holzner (ISBN 0471785970)

Let me know if you need to know more.

Cheers

Peter

Expert:

PeterNZ

Date:

Jul 19, 2006

Time:

21:56

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Hi Peter,

What I wanted to do was using ASP.NET (C#) submitting a form serverside, i.e. without actually creating an htm page and submitting that.
I found the answer and ended up with the following code:

string url = "http://websiteToSubmitTo";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string proxy = null;

string data = String.Format("parameter1={0}&parameter2={1}&parameter3={2}", parameter1, parameter2, parameter3);
byte[] buffer = Encoding.UTF8.GetBytes(data);

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.Proxy = new WebProxy(proxy, true); // ignore for local addresses
req.CookieContainer = new CookieContainer(); // enable cookies

Stream reqst = req.GetRequestStream(); // add form data to request stream
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close();

HttpWebResponse res = (HttpWebResponse)req.GetResponse();
   
Stream resst = res.GetResponseStream();
StreamReader sr = new StreamReader(resst);
string response = sr.ReadToEnd();

It's not so complicated after all.

theDude

Expert:

theDude

Date:

Jul 20, 2006

Time:

23:18

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Hey man, now I see what you wanted. Sorry that my answer wasn't helpful.

I don't know if you want to share this with us, but what actually is the requirement behind this? Just out of interest!

Cheers

Peter

Expert:

PeterNZ

Date:

Jul 20, 2006

Time:

23:48

 

Votes: Good (0) | Bad (0)
Login to rate this answer

It was the implementation of a payment gateway.
It's called nochex (nochex.co.uk) and similar to Paypal it requires that you verify "callbacks" by returning the parameters from a transaction to them and they then respond with an authorization.

Expert:

theDude

Date:

Jul 20, 2006

Time:

23:58

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Any way of using this code in a windows application and getting the result to display in a browser?

Expert:

acollings

Date:

Sep 17, 2007

Time:

19:12

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Question Answered

This question has been answered, and points have been rewarded to the following experts:

theDude: 75

You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.

 
No summaries have been submitted yet. Want to be the first?



Respond to this question:

New User

  Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:


Forgotten Password

 

New User

  Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:


Forgotten Password

   

"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it


All Questions


Language Options

English:

www.quomon.com

Español:

www.quomon.es

Sponsors

Questions and Answers Software
Real Estate Postcards
Marketing Fulfillment