473,480 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

HttpWebRequest C# to VB equiv.

I am not up with all the C# as I usually use VB, could someone explain
to me how I would accomplish this in VB? Thanks!

http://www.netomatix.com/HttpPostData.aspx
private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =

(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();
}

Nov 19 '05 #1
5 4315

"mplutodh1" <mp*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I am not up with all the C# as I usually use VB, could someone explain
to me how I would accomplish this in VB? Thanks!

http://www.netomatix.com/HttpPostData.aspx
private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =

(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();
}

Something like the following:

Private Sub OnPostInfoClick(ByVal eender As Object, ByVal e As EventArgs)
Dim strId As String = UserId_TextBox.Text
Dim strName As String = Name_TextBox.Text

Dim encoding As System.Text.ASCIIEncoding = New
System.Text.ASCIIEncoding()
Dim postData As String = "userid=" & strId
postData &= "&username=" & strName
Dim data As Byte() = encoding.GetBytes(postData)

' Prepare web request...
Dim myRequest As HttpWebRequest = DirectCast( _
WebRequest.Create(http://localhost/MyIdentity/Default.aspx), _
HttpWebRequest _
)

With myRequest
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
.ContentLength = data.Length
End With

Dim newStream As System.IO.Stream = myRequest.GetRequestStream()

' Send the data.
newStream.Write(data, 0, data.Length)
newStream.Close()
End Sub

HTH,
Mythran

Nov 19 '05 #2
So I think I converted it to some extent however the data is not being
posted to the paypal site like it should. Here is what I have:
Dim encoding As ASCIIEncoding = New ASCIIEncoding
Dim postData As String =
"cm*******************************@hotmail.com&ite m_name=Registration&item_number="
& item_number & "&amount=" & amount &
"&return=http://website.com/temp/racing.aspx?pageid=payment&strPaid=true&no_note=1& currency_code=USD&first_name="
& first_name & "&last_name=" & last_name & "address1=" & address1 &
"&city=" & city & "&state=" & zip & "&zip=" & zip & "&email=" & email &
"&night_phone_a=" & night_phone_a &""
Dim data As Byte() = encoding.GetBytes(postData)
Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("https://www.paypal.com/cgi-bin/webscr"),
HttpWebRequest)
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
Dim newStream As Stream = myRequest.GetRequestStream
newStream.Write(data, 0, data.Length)
newStream.Close
Any ideas on why it isn't posting to paypal?

Nov 19 '05 #3
Try this on for size :

Private Sub OnPostInfoClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strId As String = UserId_TextBox.Text
Dim strName As String = Name_TextBox.Text
Dim encoding As ASCIIEncoding = New ASCIIEncoding
Dim postData As String = "userid=" + strId
postData += ("&username=" + strName)
Dim data As Byte() = encoding.GetBytes(postData)
Dim myRequest As HttpWebRequest = CType(WebRequest.Create("http://localhost/MyIdentity/Default.aspx"), HttpWebRequest)
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
Dim newStream As Stream = myRequest.GetRequestStream
newStream.Write(data, 0, data.Length)
newStream.Close
End Sub

Translation to VB.NET courtesy of http://www.developerfusion.com/utili...sharptovb.aspx

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"mplutodh1" <mp*******@gmail.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com...
I am not up with all the C# as I usually use VB, could someone explain
to me how I would accomplish this in VB? Thanks!

http://www.netomatix.com/HttpPostData.aspx


private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =

(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();
}

Nov 19 '05 #4
Thanks guys, I think I have the conversion done, but my hope is the
page will redirect after posting to that form, I am using this request
to preload fields in PayPal. Any ideas on why its not working?

Nov 19 '05 #5
Courtesy of Instant VB (Demo at www.instantvb.com):

Private Sub OnPostInfoClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim strId As String = UserId_TextBox.Text
Dim strName As String = Name_TextBox.Text

Dim encoding As ASCIIEncoding = New ASCIIEncoding()
Dim postData As String="userid=" & strId
postData &= ("&username=" & strName)
Dim data As Byte() = encoding.GetBytes(postData)

' Prepare web request...
Dim myRequest As HttpWebRequest =
CType(WebRequest.Create("http://localhost/MyIdentity/Default.aspx"),
HttpWebRequest)

myRequest.Method = "POST"
myRequest.ContentType="application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
Dim newStream As Stream=myRequest.GetRequestStream()
' Send the data.
newStream.Write(data,0,data.Length)
newStream.Close()
End Sub

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
"mplutodh1" wrote:
I am not up with all the C# as I usually use VB, could someone explain
to me how I would accomplish this in VB? Thanks!

http://www.netomatix.com/HttpPostData.aspx
private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =

(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();
}

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12293
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
3
4089
by: Jerry Rhodes | last post by:
When I run the code below, the web server tells me that I need to enable cookies. Can anyone tell me what might be causing that? I'm trying to POST userid and password to their login web page. ...
9
4897
by: Mangesh | last post by:
hi, I am using HTTPWebrequest object to download google results. in the response stream I am not getting some foreign characters eg. If I search "signo de pregunta", all the spanish characters are...
9
8146
by: Mike Cronin via DotNetMonster.com | last post by:
Hi there, Can anyone tell me what level of encryption is used when making an HTTPS POST request through an instance of the System.Net.HttpWebRequest object? Thanks much in advance! Mike...
16
12608
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
1
2584
by: sfoxover | last post by:
Hi, Could someone please give me some suggestions on how to make this class robust. I need to be able to handle around 20 similtanious requests to this class which causes a web browser to...
6
4147
by: Mike Koerner | last post by:
Hi, I am having problems setting the HttpWebRequest Date header. I understand that it is a restricted header and I do receive the "This header must be modified with the appropriate property." ...
1
7979
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
15
3072
by: Nightcrawler | last post by:
I am currently using the HttpWebRequest and HttpWebResponse to pull webpages down from a few urls. string url = "some url"; HttpWebRequest httpWebRequest =...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.