HTTP Post keep alive and chunked

In Visual Basic ....VB.Net, or Windows Service whatever...
I need to post some XML using the following setup

Instructions: "HTTP chunked encoding includes the header "Transfer-Encoding:chunked " and the length of the chunk (plus newline) before actual chunk"

POST /bot1/bot1 HTTP/1.1
Connection:  keep-alive
Content-Type: text/plain
Transfer-Encoding: chunked

Lets say for example I need to post this
   <clientID> 123</clientID>

I have this so far...but not sure what to do with the code between the ======= marks and how to implement the
"length of chunk plus new line"  part

 Public Sub GetXmlChunkedData(ByVal URI As String, ByVal Parameters As String)
        Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(URI)

        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing

            ' Create the web request   
            request = DirectCast(WebRequest.Create(URI), HttpWebRequest)
            request.ContentType = "text/plain"
            request.Method = "POST"
            request.KeepAlive = True
            request.TransferEncoding = "chunked"
            request.UserAgent = "CometTest"

            'Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes(Parameters)
            'request.ContentLength = bytes.Length
            'Dim os As System.IO.Stream = request.GetRequestStream()
            'os.Write(bytes, 0, bytes.Length)

            '' Get response   
            'response = DirectCast(request.GetResponse(), HttpWebResponse)

            '' Load data somewhere

            If Not response Is Nothing Then response.Close()
        End Try

    End Sub

Open in new window

Who is Participating?
David Johnson, CD, MVPConnect With a Mentor OwnerCommented:
Each chunk starts with the number of octets of the data it embeds expressed in hexadecimal followed by optional parameters (chunk extension) and a terminating CRLF (carriage return and line feed) sequence, followed by the chunk data. The last chunk is a zero-length chunk, with the chunk size coded as 0, but without any chunk data section.
lrbristerAuthor Commented:

Ok...I recognized the vowels and consonets.

But little else in your answer.  

I need to do this in Visual Basic. You have a different link?
lrbristerAuthor Commented:
I wasn;t clear enough.
This gives me the information, but in a different environment
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.