I am sending a POST request to an API server and I have reused code where I have successfully done this before on other servers and for some reason, which I cannot figure out why, it's not working. I get the error:

Cannot close stream until all bytes are written."}

even though I declared the content length correctly and I am not sure what I am missing here...
Code:
                data = data + "</posts>"
                Dim postBytes As [Byte]() = Encoding.UTF8.GetBytes(data)
                Thread.Sleep(10000)
                track = data
                If uri.Scheme = uri.UriSchemeHttps Then
                    Dim request As HttpWebRequest = HttpWebRequest.Create(url)
                    request.Method = "POST"
' normally I just use request.contentlength = postbytes.length or data.length
                    request.ContentLength = System.Text.Encoding.UTF8.GetByteCount(data)
                    request.ContentType = "application/xml"
                    request.KeepAlive = False
                    request.Timeout = 120000
                    request.Credentials = New System.Net.NetworkCredential("xxxxxxxxxxxx", "xxxxxxxxx")

                    Using writer As New StreamWriter(request.GetRequestStream(), Encoding.UTF8)
                        writer.Write(postBytes)
                        writer.Flush()
                        writer.Close()
                    End Using
                    Using oResponse As HttpWebResponse = request.GetResponse()
                        Dim reader As New StreamReader(oResponse.GetResponseStream())
                        responseData = reader.ReadToEnd()
                        reader.Close()
                        oResponse.Close()
                    End Using
                    request.Abort()
                   
                End If
              
            End If
        Catch e As WebException
....
Any ideas please...