Forum Moderators: open

Message Too Old, No Replies

HTTPPOST using .NET

need some help

         

mattglet

5:12 pm on Jun 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i have looked around, and i'm not finding an easy way to perform an HTTPPOST using .NET (vb).

background:
i have a form that, upon completion, inserts the values into my database. i need to then push these values to another site to be inputted into that db. i was hoping to use HTTPPOST. can anyone point me in the right direction to performing this task? i think i have to use the httpwebrequest class, but i'm not entirely sure. thanks.

-Matt

webdevsf

5:28 pm on Jun 16, 2003 (gmt 0)

10+ Year Member



Write a web service (.asmx) file. It's easier and does type checking for you, and you call it like you would any other object.

mattglet

5:49 pm on Jun 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



not sure if you understood my question...

i'm trying to post the data to a 3rd party site (so i will have no control of the data once it's passed).

once the data is passed, i want to then receive back the site's response to the data (approval, denial, etc).

-Matt

ziggystardust

1:10 pm on Jun 17, 2003 (gmt 0)

10+ Year Member



You can do this by using the WebRequest class. Unfortunately, I can't show you how to do this in VB.NET, only C#, so you'll have to translate it.


string postData = "name=ziggy&occ=singer"; [i]// Separate each field in the form with a &[/i]
string useURL = "http://www.ilikethisurl.com/default.aspx";


[i]// Create an instance of the WebRequest class[/i]
WebRequest objRequest = WebRequest.Create(useURL);
objRequest.Timeout = 60000; [i]// In milliseconds - in this case 60 seconds[/i]
objRequest.Method = "POST";
objRequest.ContentLength = postData.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";


[i]// Create an instance of the StreamWriter class and attach the WebRequest object to it - here's where we do the posting[/i]
StreamWriter postWriter = new StreamWriter(objRequest.GetRequestStream());
postWriter.Write(postData);
postWriter.Close();


[i]// Create an instance of the WebResponse class and get the output to the rawOutput string[/i]
WebResponse objResponse = objRequest.GetResponse();
StreamReader sr = new StreamReader(objResponse.GetResponseStream());
string rawOutput= sr.ReadToEnd();
sr.Close();

Also, I recommend you add some exception handling, for what happens when the connection times out, can't find server etc. etc.

Good luck

//ZS

mattglet

7:30 pm on Jun 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ziggy -
greatly appreciate your code... i will be saving that. but i have found, that i need to do something different.

background:
i am collecting data via asp.net form. this data gets submitted to verisign for the customer to enter their payment info. all i need to do is post data TO verisign, NOT postback, which is impossible with .NET. i cannot use the WebRequest class, because i need the user to stay on verisign's site. hopefully that's understandable...

should i be using server.transfer? i need to pass the variables, but i cannot have the data in the querystring.

-Matt

sharbel

12:20 am on Jun 18, 2003 (gmt 0)

10+ Year Member



You should be working in conjunction with the payment provider.. They should have some info on how to do it, since by nature they will have strict security in place.. so conventional methods just might not work.

mattglet

1:48 am on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sharbel -
this isn't an issue with the payment provider, this is an issue with .NET not being able to post data via client side forms to other sites. i'm wondering if anyone has found a work-around.

-Matt

sharbel

1:50 am on Jun 18, 2003 (gmt 0)

10+ Year Member



Check out Paul Wilson's free form control then.. it will allow you to post to another page :) .. i dont have the link handy but if you do a search it will come up.. either that or do a search on www.asp.net in the forums