我的代码是
resp = HTTParty.get("http://sandbox.api.simsimi.com/request.p?key=e7501386-fca8-4723-b278-36755e917526&lc=ko&ft=1.0&text=#{params[:content]}")
和params [: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
更多信息在这里:Ruby URL编码字符串
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句