I am trying to implement PayPal IPN functionality. The basic protocol is as such:
I know it's a bit late to chime in here, but the best solution I found was to not even parse what they were giving back. In django (don't know what you're using) I was able to get the raw request they sent, which I passed back verbatim. Then it was just a matter of putting the cmd key onto that.
This way it never matters what encoding they send you, you're just sending it right back.