我正在处理rails应用程序中的一些#标签处理。
告诉我们,我编写了一个端点,通过params
hash接收包含一些主题标签的字符串。有些人喜欢这样
This string contains this #hashtag and this #one
。
我正在使用邮递员来测试我的终端。
现在,当我在邮递员中时,我会执行以下操作:
{{url}}/add?content=content=This string contains this #hashtag and this #one
我在params
收到字符串"content"=>"This string contains this "
。也就是说,从符号#
的第一次出现开始,剩余的字符串被切断。
非常清楚我的问题是天真的,我敢问为什么?我做错了什么?我如何管理传递包含#
符号的字符串?
你需要确保you encode无论你在param发送什么。
URI.encode("This string contains this #hashtag and this #one")
#=> This%20string%20contains%20this%20%23hashtag%20and%20this%20%23one
更新你的邮递员请求,用#
替换%23
{{url}}/add?content=This string contains this %23hashtag and this %23one
在将来做这样的事情时你可以选择一部分参数(或整个事物)并右键单击并选择EncodeURIComponent
,如here所述