PROTOTYPE MESSAGE SERVER

5.2.1 HTTP POST from Client

The following code performs a HTTP POST with the text that is in the send textbox:

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 ' Create a new string object to POST data to the Url.
   Dim myHttpWebRequest As HttpWebRequest
   Dim encoding As New ASCIIEncoding


   myHttpWebRequest = myHttpWebRequest.Create(txtServer.Text & "/" & txtSendQueue.Text)
   ' Set the content type of the data being posted.
    myHttpWebRequest.ContentType = "text/xml" '"application/x-www-form-urlencoded"
 
   myHttpWebRequest.Method = "POST"
    ' Set the content length of the string being posted.
 
   myHttpWebRequest.ContentLength = txtMessage.Text.Length
    Dim newStream As Stream = myHttpWebRequest.GetRequestStream
    newStream.Write(encoding.GetBytes(txtMessage.Text), 0,
    encoding.GetBytes(txtMessage.Text).Length)
    newStream.Flush()
    newStream.Close()
 End Sub