The problem is that you are sending your HTTP request before adding your payload, resulting in a message
exchange like this:
You should be calling
getResponseCode() after setting your payload, which would result in a message exchange like this:
For example, using your code: