Josh Gilman has posted a new class that he's developed to make it simple to create the HTTP headers for any connection.
It also reads back the host's reply and parses any header and cookie information. Supports GZIP encoding as well. The source can be seen here. Feel free to use it, just don't take any credit for yourself. More to come soon!
The code is pretty simple - all OOP and in a class to make it easy and the assemble_header function makes you a single function call away from your shiny new headers for your message.