Skip to content

Instantly share code, notes, and snippets.

@jeffque
Last active February 11, 2021 14:47
Show Gist options
  • Select an option

  • Save jeffque/414a2aad25c94f3296363b1e5ef21454 to your computer and use it in GitHub Desktop.

Select an option

Save jeffque/414a2aad25c94f3296363b1e5ef21454 to your computer and use it in GitHub Desktop.
Fazendo GET com cabeçalhos usando o HTTP padrão do Ruby
require "uri"
require "net/http"
uri = URI.parse 'meu_endpoint'
requisicao = NET::HTTP::GET.new uri
requisicao['my_header'] = 'valor'
# na documentação também fala do método .add_field
# requisicao.add_field 'my_header', 'valor'
# parece que o add_field ajuda quando o header é uma espécie de vetor
resultado = NET::HTTP.start uri.hostname, uri.port do |http|
http.request requisicao
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment