System.IO.IOException: Cannot close stream until all bytes are written when sending webrequest

I am trying to send a web request but am getting the following error:
"System.IO.IOException: Cannot close stream until all bytes are written."
on the following line

Here is my code snippet

objRequest = CType(WebRequest.Create(post_url), HttpWebRequest)
        objRequest.Method = "POST"
        objRequest.ContentLength = 54
        objRequest.ContentType = "application/x-www-form-urlencoded"
        objRequest.Headers("Authorization") = "BASIC " & authorization_string

        post_string = "&command=requestnewpassword&application=netconnect"

        ' post data is sent as a stream
        myWriter = Nothing
        myWriter = New StreamWriter(objRequest.GetRequestStream())

Anyone have any ideas how to fix this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try calling the Flush before close.
Obadiah ChristopherDeveloper User InterfaceCommented:
Maybe u could add a try and call the close method in finally block
DEWebWorksAuthor Commented:
I tried adding myWriter.Flush() just before the close line, but it didn't change anything.
DEWebWorksAuthor Commented:
So, it turns out that this line:

objRequest.ContentLength = 54

should have been
objRequest.ContentLength = 50

Thanks for the help.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DEWebWorksAuthor Commented:
I found the answer elsewhere, but wanted to show the answer for others that might encounter this same problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.