Hi
How about this code? from msdn..
' Create a new request to the mentioned URL.
Dim myWebRequest As WebRequest =
WebRequest.Create("http://www.contoso.com/codesnippets/next.asp")
' Create an instance of the RequestState and assign
'myWebRequest' to it's request field.
Dim myRequestState As New RequestState()
myRequestState.request = myWebRequest
myWebRequest.ContentType = "application/x-www-form-urlencoded"
' Set the 'Method' prperty to 'POST' to post data to a Uri.
myRequestState.request.Method = "POST"
myRequestState.request.ContentType =
"application/x-www-form-urlencoded"
' Start the Asynchronous 'BeginGetRequestStream' method call.
Dim r As IAsyncResult =
CType(myWebRequest.BeginGetRequestStream(AddressOf ReadCallback,
myRequestState), IAsyncResult)
' Assign the response object of 'WebRequest' to a
'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
Console.WriteLine(ControlChars.Cr + "The string entered
has been successfully posted to the Uri")
Console.WriteLine("Please wait for the response.......")
Dim streamResponse As Stream = myWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
Console.WriteLine(ControlChars.Cr + "The contents of the
HTML page are ")
While count > 0
Dim outputData As New [String](readBuff, 0, count)
Console.WriteLine(outputData)
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream Object.
streamResponse.Close()
streamRead.Close()
allDone.WaitOne()
' Release the HttpWebResponse Resource.
myWebResponse.Close()
Catch e As WebException
Console.WriteLine(ControlChars.Cr + "WebException Caught!")
Console.WriteLine("Message :{0}", e.Message)
Catch e As Exception
Console.WriteLine(ControlChars.Cr + "Exception Caught!")
Console.WriteLine("Message :{0}", e.Message)
End Try
End Sub ' Main
Private Shared Sub ReadCallback(asynchronousResult As IAsyncResult)
Try
' State of request is set to asynchronous.
Dim myRequestState As RequestState =
CType(asynchronousResult.AsyncState, RequestState)
Dim myWebRequest2 As WebRequest = myRequestState.request
' End of the Asynchronus request.
Dim streamResponse As Stream =
myWebRequest2.EndGetRequestStream(asynchronousResult)
' Create a string that is to be posted to the uri.
Console.WriteLine(ControlChars.Cr + "Please enter a string
to be posted to (http://www.contoso.com/codesnippets/next.asp) Uri:")
Dim inputData As String = Console.ReadLine()
Dim postData As String = "firstone" + ChrW(61) + inputData
Dim encoder As New ASCIIEncoding()
' Convert the string into a byte array.
Dim ByteArray As Byte() = encoder.GetBytes(postData)
' Write data to the stream.
streamResponse.Write(ByteArray, 0, postData.Length)
streamResponse.Close()
allDone.Set()
Catch e As WebException
Console.WriteLine(ControlChars.Cr + "WebException Caught!")
Console.WriteLine("Message :{0}", e.Message)
Catch e As Exception
Console.WriteLine(ControlChars.Cr + "Exception Caught!")
Console.WriteLine("Message :{0}", e.Message)
End Try
End Sub ' ReadCallback
thanks
bala |