Groups | Blog | Home
all groups > dotnet faqs > october 2004 >

dotnet faqs : How to POST data


Girish bharadwaj
10/24/2004 8:43:31 AM
Pretty much x=y&r=t&l=blah.. so on..

--
Girish Bharadwaj
http://msmvps.com/gbvb
[quoted text, click to view]
The following is the documentation on the WebClient Class in the VS .NET on
POSTing data to a web page. My question is how do I enter the FORM
parameters? Is it xxx=aaaaa? How to I separate multiple parameters?
Thanks in advance.

[Visual Basic]

Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to{for
example, http://www.contoso.com} : ")
uriString = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to
the URI {0}:", uriString)
Dim postData As String = Console.ReadLine()
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
' Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
' Upload the input string using the HTTP 1.0 POST method.
Dim responseArray As Byte() = myWebClient.UploadData(uriString, "POST",
byteArray)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}",
Encoding.ASCII.GetString(responseArray))

Sam Low
10/24/2004 5:58:02 PM
This is a multi-part message in MIME format.

------=_NextPart_000_006A_01C4B9F3.01294590
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

The following is the documentation on the WebClient Class in the VS .NET =
on POSTing data to a web page. My question is how do I enter the FORM =
parameters? Is it xxx=3Daaaaa? How to I separate multiple parameters? =
Thanks in advance.

[Visual Basic]

Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data =
to{for example, http://www.contoso.com} : ")
uriString =3D Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted =
to the URI {0}:", uriString)
Dim postData As String =3D Console.ReadLine()
myWebClient.Headers.Add("Content-Type", =
"application/x-www-form-urlencoded")
' Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray As Byte() =3D Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
' Upload the input string using the HTTP 1.0 POST method.
Dim responseArray As Byte() =3D myWebClient.UploadData(uriString, =
"POST", byteArray)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}", =
Encoding.ASCII.GetString(responseArray))
------=_NextPart_000_006A_01C4B9F3.01294590
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.3790.218" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>The following is the documentation on =
the WebClient=20
Class in the VS .NET on POSTing data to a web page.&nbsp; My question is =
how do=20
I&nbsp;enter the FORM parameters?&nbsp;&nbsp; Is it xxx=3Daaaaa?&nbsp; =
How to I=20
separate multiple parameters?&nbsp; Thanks in advance.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT size=3D2>[Visual =
Basic]</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2><BR></FONT><FONT face=3D"Arial =
Narrow"=20
size=3D2>Dim uriString As String<BR>Console.Write(ControlChars.Cr + =
"Please enter=20
the URI to post data to{for example, http://www.contoso.com} : =
")<BR>uriString =3D=20
Console.ReadLine()<BR>' Create a new WebClient instance.<BR>Dim =
myWebClient As=20
New WebClient()<BR>Console.WriteLine(ControlChars.Cr + "Please enter the =
data to=20
be posted to the URI {0}:", uriString)<BR><FONT color=3D#ff0000>Dim =
postData As=20
String =3D =
Console.ReadLine()<BR></FONT>myWebClient.Headers.Add("Content-Type",=20
"application/x-www-form-urlencoded")<BR>' Apply ASCII Encoding to obtain =
the=20
string as a byte array.<BR>Dim byteArray As Byte() =3D=20
Encoding.ASCII.GetBytes(postData)<BR>Console.WriteLine("Uploading to {0} =
....",=20
uriString)<BR>' Upload the input string using the HTTP 1.0 POST =
method.<BR>Dim=20
responseArray As Byte() =3D myWebClient.UploadData(uriString, "POST",=20
byteArray)<BR>' Decode and display the=20
response.<BR>Console.WriteLine(ControlChars.Cr + "Response received was =
:{0}",=20
Encoding.ASCII.GetString(responseArray))</FONT></FONT></DIV></BODY></HTML=
[quoted text, click to view]

------=_NextPart_000_006A_01C4B9F3.01294590--
AddThis Social Bookmark Button