Skip to content

Instantly share code, notes, and snippets.

@natereed
Created January 17, 2013 23:10
Show Gist options
  • Save natereed/4560770 to your computer and use it in GitHub Desktop.
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.
def encode_post_params(params)
params.map do |param|
name = param['name']
value = param['value']
"#{CGI.escape(name)}=#{CGI.escape(value)}"
end.join('&')
end
@natereed
Copy link
Author

The key thing here is CGI.escape. This will properly encode spaces as +'s and all other non-alphanumeric characters using their numeric codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment