我尝试在Ruby中使用Net::HTTP::Get在URL中传递一个值,我需要这样做:
https://cdpj.partners.bancointer.com.br/pix/v2/webhook/{18497418000111}
但我不知道怎么做,这是我的代码:
require 'net/http'
require 'net/https'
require 'json'
uri = URI.parse("https://cdpj.partners.bancointer.com.br/pix/v2/webhook/{18497418000111}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request["Authorization"] = "Bearer #{'1fd64146-xxxx-xxxx-xxxx-xxxx997c170'}"
request["Accept"] = "application/vnd.bluebadge-api.v1+json"
response = http.request(request)
当我试着去做的时候,我收到了这样的信息:错误的URI(不是URI?):“https://cdpj.partners.bancointer.com.br/pix/v2/webhook/{18497418000111}”
但是如果我尝试在url中插入我的param,一切都按预期工作:
基本上我的问题是,如何在我的URI中添加我的URL的这一部分:{18497418000111}**使用json我需要添加一个键/值,但在我的示例中我只需要传递值。
谢谢你,谢谢!
1条答案
按热度按时间mrzz3bfm1#
当我试着去做的时候,我收到了这样的信息:错误的URI(不是URI?):“https://cdpj.partners.bancointer.com.br/pix/v2/webhook/{18497418000111}”
如果你用十六进制代码编码
{
和}
字符,那么它就可以工作。请参阅下面的irb
输出。编码前
编码后