Change from urlencode to rawurlencode. This should prevent the spaces and + to get lost.