发出 GET 请求并接收参数
我正在开发 Ruby on Rails 应用程序。我必须向以下发出 GET 请求:
https://[@subdomain].chargify.com/subscriptions/[@subscription.id].json
收到的响应将是 json。我试图通过使用 ruby 的“net/http”库发出 GET 请求来实现此目的,我的代码如下:
res = Net::HTTP.get(URI.parse('https://[@subdomain].chargify.com/subscriptions/[@subscription_id].json'))
但我收到一个错误:
错误的 URI(不是 URI?): https://[@subdomain].chargify.com/subscriptions/[@subscription_id].json
我不确定我到底在哪里犯了错误。任何建议或帮助将不胜感激。
谢谢
I am working on a Ruby on Rails App.I have to make a GET request to following:
https://[@subdomain].chargify.com/subscriptions/[@subscription.id].json
The response received is going to be json. I am trying to achieve this by making the GET request using the 'net/http' library of ruby and my code is as follows :
res = Net::HTTP.get(URI.parse('https://[@subdomain].chargify.com/subscriptions/[@subscription_id].json'))
But I am getting an error which is :
bad URI(is not URI?):
https://[@subdomain].chargify.com/subscriptions/[@subscription_id].json
I am not sure where exactly am I making mistake with this. Any suggestions or help would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的意思是
#{@subdomain}
而不是[@subdomain]
吗?它必须位于双引号"
内才能正确插值。Do you mean
#{@subdomain}
instead of[@subdomain]
? That has to be inside of double quotes"
in order to get interpolated properly.现在您知道您的错误是您没有正确插入字符串。您应该指定 #{@subdomain} 而不是 [@subdomain],并且您需要用双引号将字符串括起来。
您现在遇到的问题是您需要告诉 http 连接使用SSL。我用这样的东西..
By now you know that your error was that you didn't interpolate the string correctly. You should have specified #{@subdomain} rather than [@subdomain] and you need double quotes around the string
The problem that you now have is that you need to tell the http connection to use ssl. I use something like this ..
两件事:
@subdomain 的值需要使用
传递
<前><代码>#{@子域}
连接是ssl来传递
然后
要执行get动作
Two things:
The value of @subdomain needs to be passed using
The connection is ssl
Then
To perform get actions