Ruby on rails 如何在URL中发送韩语字符串?(使用HTTParty gem的Ruby on Rails)

Ruby on rails 如何在URL中发送韩语字符串?(使用HTTParty gem的Ruby on Rails),ruby-on-rails,ruby,http,httparty,Ruby On Rails,Ruby,Http,Httparty,我的代码是 resp = HTTParty.get("http://sandbox.api.simsimi.com/request.p?key=e7501386-fca8-4723-b278-36755e917526&lc=ko&ft=1.0&text=#{params[:content]}") 参数[:content]是”안녕"现在 如果我运行这个代码 我得到以下错误 URI must be ascii only "http://sandbox.api.simsimi

我的代码是

resp = HTTParty.get("http://sandbox.api.simsimi.com/request.p?key=e7501386-fca8-4723-b278-36755e917526&lc=ko&ft=1.0&text=#{params[:content]}")
参数[:content]是
”안녕"现在

如果我运行这个代码

我得到以下错误

URI must be ascii only "http://sandbox.api.simsimi.com/request.p?key=e7501386-fca8-4723-b278-36755e917526&lc=ko&ft=1.0&text=\u00ED\u0095\u0098\u00EC\u009D\u00B4" (URI::InvalidURIError)
如何在URL中发送韩语字符串

(.encode("utf-8) is not working..)
由于错误消息显示“URI必须仅为ascii”,您可以将韩语编码为URI格式,如下所示

require 'uri'
str = "안녕".force_encoding('ASCII-8BIT') # "\xEC\x95\x88\xEB\x85\x95"
URI::encode(str) # %EC%95%88%EB%85%95
更多信息如下: