开发者

use html formatted uri in Ruby

开发者 https://www.devze.com 2023-02-04 03:58 出处:网络
I need to send mails via a webapi (Dreamhost). By accessing a url with encoded parameters you can define the email.

I need to send mails via a webapi (Dreamhost). By accessing a url with encoded parameters you can define the email.

one of the parameters is the message in html format.

I use the open() method to acces the url but get a

URI::InvalidURIError

I can reformat the url by using URI.parse and URI.encode but this reformats the html in a unwa开发者_运维百科nted state.

Is there a way I can embed html and open the url in Ruby?

Thanks


Use CGI.escape.

require 'cgi'
"http://example.com?message=#{CGI.escape('This is the message body!')}"
0

精彩评论

暂无评论...
验证码 换一张
取 消