added a section to read the header from the server, and parse the response to make sure its legal.