Ruby rl as¶m=¶m=即使没有值。谢谢。好的,我想这可能是正确的解决方案。但目前它无法识别短语作为参数。@user3162553您可以这样做来解决问题,将:url hostname替换为127.0.0.1:8888或localhost:88
Ruby rl as¶m=¶m=即使没有值。谢谢。好的,我想这可能是正确的解决方案。但目前它无法识别短语作为参数。@user3162553您可以这样做来解决问题,将:url hostname替换为127.0.0.1:8888或localhost:88,ruby,sinatra,Ruby,Sinatra,rl as¶m=¶m=即使没有值。谢谢。好的,我想这可能是正确的解决方案。但目前它无法识别短语作为参数。@user3162553您可以这样做来解决问题,将:url hostname替换为127.0.0.1:8888或localhost:8888(8888只是一个随机端口号,使用适合您的端口号),然后在另一个术语中运行类似于nc-l 8888(nc是netcat工具)。然后执行RestClient::Request并检查RestClient发送给netcat的请求。好的,我发现了问
rl as¶m=¶m=即使没有值。谢谢。好的,我想这可能是正确的解决方案。但目前它无法识别短语作为参数。@user3162553您可以这样做来解决问题,将:url hostname替换为127.0.0.1:8888或localhost:8888(8888只是一个随机端口号,使用适合您的端口号),然后在另一个术语中运行类似于
nc-l 8888
(nc是netcat工具)。然后执行RestClient::Request并检查RestClient发送给netcat的请求。好的,我发现了问题-如果不是nil,我只需要传递参数。它将参数作为¶m=¶m=传递到url中,即使没有值。谢谢
post '/search' do
phrase = params.fetch "phrase" #mandatory
@delimiters = ""
start_date = params.fetch "start_date"
start_date.empty? ? start_date = "" : @delimiters << "From #{start_date},"
end_date = params.fetch "end_date"
end_date.empty? ? end_date = "" : @delimiters << "To #{end_date}"
api_result = RestClient::Request.execute(method: :get, url: "capitolwords.org/api/1/text.json?phrase=#{phrase}
&page=0&apikey=",
headers: {params: {:start_date => start_date,
:end_date => end_date},
:Authorization => ENV['SUNLIGHT_API_KEY']},
timeout: 10)
end
api_result = RestClient::Request.execute(method: :get,
url: "capitolwords.org/api/1/text.json",
headers: {params: {:phrase => phrase,
:start_date => start_date,
:end_date => end_date,
:page => 0,
:apikey => ENV['SUNLIGHT_API_KEY']}},
timeout: 10)
require 'dotenv'
Dotenv.load