Fixed content-length bug. Added callback on error.

Using a buffer fixes a bug that leads to a wrong content-length when the json body contains unicode characters.
Call callback when an error occured as there will be no other callback call.