Ruby Typhoeus 请求:带引号的 url
我在使用 Typhoeus 执行请求时遇到问题,因为我的查询需要包含引号。
如果 URl 是
url = "http://app.com/method.json?'my_query'"
一切正常。但是,如果查询如下(我已在浏览器中测试过),我尝试运行的方法仅返回我想要的结果:
url2 = "http://app.com/method.json?"my_query""
运行时
Typhoeus::Request.get(url2)
我得到 (URI::InvalidURIError)
Escapeingquotes with "\" does not工作。我该怎么做?
谢谢
I'm having a problem doing a request using Typhoeus as my query needs to have quotation marks into it.
If the URl is
url = "http://app.com/method.json?'my_query'"
everything works fine. However, the method I'm trying to run only returns the results I want if the query is the following (i've tested it in browser):
url2 = "http://app.com/method.json?"my_query""
When running
Typhoeus::Request.get(url2)
I get (URI::InvalidURIError)
Escaping quotes with "\" does not work. How can I do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用
正确编码您的 URI URI.encode
或CGI.escape
,这样做将为您提供正确的 URL,如下所示:You should be properly encoding your URI with
URI.encode
orCGI.escape
, doing so will get you proper URLs like this:尝试:
Try:
在 GET 请求中传递 json、引号等很棘手。在 Ruby 2+ 中,我们可以使用 Ruby 的 URI 模块的“转义”方法。
但我建议将其用作 POST 请求并将其作为消息正文传递。
Passing json, quotes etc in GET request is tricky. In Ruby 2+ we can use Ruby's URI module's 'escape' method.
But I suggest use it as POST request and pass it as a message body.