Created
January 17, 2013 23:10
-
-
Save natereed/4560770 to your computer and use it in GitHub Desktop.
Convert a postParams hash from an HAR file into a URL-encoded string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encode_post_params(params) | |
params.map do |param| | |
name = param['name'] | |
value = param['value'] | |
"#{CGI.escape(name)}=#{CGI.escape(value)}" | |
end.join('&') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The key thing here is CGI.escape. This will properly encode spaces as +'s and all other non-alphanumeric characters using their numeric codes.