【发布时间】:2020-11-27 15:16:00
【问题描述】:
我是 ruby RestClient 的新手。我已经搜索了这个 restclient 和 docruby 的许多示例。对我来说,使用 ruby restclient 非常重要,可以非常快速地获取数据。 但有些不是答案,这就是我想向大家提问的原因。
我正在研究这个 ruby restclient 示例代码:
restClient = RestClient::Request.new(
:method => :get,
:url => url,
:verify_ssl => true, #required using https
:content_type => :json,
:accept => :json,
:headers => {
:Authorization => "Bearer #{token}",
}
)
result = restClient.execute()
我的第一个问题是使用双点和天文望远镜有什么不同?
restClient = RestClient::Request.new(
:method => :get,
:method => 'get',
...
)
第二个问题是,代码中的序列/顺序是否重要,例如第一个 url 然后方法或方法然后 url 等等?
restClient = RestClient::Request.new(
:url => :url,
:method => :get,
...
)
#or
restClient = RestClient::Request.new(
:method => :get,
:url => :url,
...
)
第三个问题是,关于接受放入标题。有的在 header 中放了 accept 和 content-type,有的没有,有什么不同?
restClient = RestClient::Request.new(
:content_type => 'application/json',
:accept => 'application/json',
#or
:headers => {
'hello-token' => "Bearer #{token}",
'content_type'=> 'application/json',
'ACCEPT' => 'application/json'
}
)
【问题讨论】:
-
如果您有三个问题,请提出三个问题,让每个问题都能得到应有的答案。但是,请注意问题 #1 和 #2 与
RestClient无关,它们只是基本的 Ruby 语法问题,在每个基本 Ruby 教程中都有介绍,并且已经在 Stack Overflow 上被多次询问和回答。此外,如果您能准确地解释 什么 您对文档不清楚,这将有所帮助,这样回答者就不会浪费时间告诉您您已经知道的东西,或者您已经阅读和没有阅读的东西'不懂。
标签: ruby gitlab rest-client gemfile