Help! How to HTTP Post in Dot Net??

E

Ed

I'm trying to port one of my applications from VB6 to Dot Net.

In my VB6 app I do an HTTP Post of data to a website and receive a
response. I want to essentially do the same thing in VB Dot Net.

This is my original VB6 source code:

WinHttpReq.Open "POST", "https://www.abcdefg.com/ProcessInquiry.asp",
False
WinHttpReq.SetRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
WinHttpReq.Send sSendText
sResponseText = WinHttpReq.ResponseText

What is the equivalent in dotnet? I need to be able to send sSendText
and get a result sResponseText.

Thanks in advance.
ed
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Ed,

The .NET counterpart is the WebRequest class. Its interface differs from
what you had in VB6 but the concept is pretty much the same - specify
method, add headers and cookies and issue the request. To obtain the
response as text, you should use the HttpResponseStream class to read
response bytes which will be then converted to a string with the
System.Text.Encoding.GetString method.
 
E

Ed

Thanks Dmitriy,

What is the equivalent for this line? WebRequest doesn't seem to have
an interface to send data.
WinHttpReq.Send sSendText

ed

Dmitriy Lapshin said:
Hi Ed,

The .NET counterpart is the WebRequest class. Its interface differs from
what you had in VB6 but the concept is pretty much the same - specify
method, add headers and cookies and issue the request. To obtain the
response as text, you should use the HttpResponseStream class to read
response bytes which will be then converted to a string with the
System.Text.Encoding.GetString method.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ed said:
I'm trying to port one of my applications from VB6 to Dot Net.

In my VB6 app I do an HTTP Post of data to a website and receive a
response. I want to essentially do the same thing in VB Dot Net.

This is my original VB6 source code:

WinHttpReq.Open "POST", "https://www.abcdefg.com/ProcessInquiry.asp",
False
WinHttpReq.SetRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
WinHttpReq.Send sSendText
sResponseText = WinHttpReq.ResponseText

What is the equivalent in dotnet? I need to be able to send sSendText
and get a result sResponseText.

Thanks in advance.
ed
 
D

Dmitriy Lapshin [C# / .NET MVP]

The request body is transferred through the GetRequestStream:

Dim formBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(sText)
request.ContentLength = formBytes.Length

Dim requestData As Stream = request.GetRequestStream()

Try
requestData.Write(formBytes, 0, CInt(request.ContentLength))
Finally
requestData.Close()
End Try

P.S. There are syntax errors possible in the example above - I'm a C# guy
after all :)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ed said:
Thanks Dmitriy,

What is the equivalent for this line? WebRequest doesn't seem to have
an interface to send data.
WinHttpReq.Send sSendText

ed

"Dmitriy Lapshin [C# / .NET MVP]" <[email protected]> wrote
in message news: said:
Hi Ed,

The .NET counterpart is the WebRequest class. Its interface differs from
what you had in VB6 but the concept is pretty much the same - specify
method, add headers and cookies and issue the request. To obtain the
response as text, you should use the HttpResponseStream class to read
response bytes which will be then converted to a string with the
System.Text.Encoding.GetString method.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ed said:
I'm trying to port one of my applications from VB6 to Dot Net.

In my VB6 app I do an HTTP Post of data to a website and receive a
response. I want to essentially do the same thing in VB Dot Net.

This is my original VB6 source code:

WinHttpReq.Open "POST", "https://www.abcdefg.com/ProcessInquiry.asp",
False
WinHttpReq.SetRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
WinHttpReq.Send sSendText
sResponseText = WinHttpReq.ResponseText

What is the equivalent in dotnet? I need to be able to send sSendText
and get a result sResponseText.

Thanks in advance.
ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top