Not bad.

Would reduce the amount of code and increase the efficiency overall to use cURL though rather than manually writing headers and such to a socket.