1

Ruby on Rails App.I に取り組んでいます。次の 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

これでどこを間違えているのか正確にはわかりません。提案や助けをいただければ幸いです。

ありがとう

4

3 に答える 3

1

#{@subdomain}の代わりということ[@subdomain]ですか?"適切に補間するには、二重引用符で囲む必要があります。

于 2011-07-07T19:37:00.137 に答える
1

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 ..

http = Net::HTTP.new(uri.host, uri.port)

http.use_ssl = true

request = Net::HTTP::Get.new(uri.request_uri)
于 2011-07-07T21:42:36.550 に答える
0

2つのこと:

  1. @subdomainの値は、を使用して渡す必要があります

    #{@subdomain}
    
  2. 接続はsslです

    def net_http(uri)
    h = Net::HTTP.new(uri.host, uri.port)
    h.use_ssl=true
            h
    end
    

それで

     request=net_http(URI.parse("https://#       {@subdomain}.chargify.com/subscriptions/#{@subscription_id}.json"))

getアクションを実行するには

     request=net_http(URI.parse("https://#       {@subdomain}.chargify.com/subscriptions/#{@subscription_id}.json")).start do |http|
        http.get(URI.parse("whatever_url").path,{:params=>123})
        end 
于 2011-07-08T04:42:04.227 に答える