Handle http errors so node.js doesn't crash.
Fix content length calculation

Before, the length was 2 bytes shorter than the data being sent, so the
remote end would reset the connection before all the data was sent.

Used Buffer.byteLength() instead of plain string length so that we don't
run into trouble when non-ASCII characters are present.