Check error before defer response body close

Hi,
When an error occurs during http post, the body is nil and trying to close the body would cause the program to panic. Therefore, it would be better to check error right after http post.

thanks

km