change url encoding and add a test

Use http_build_query for encoding