使用Sinatra在hashtag之后捕获URL参数

时间:2021-11-05 08:28:48

I'm trying to capture the URL parameters from the following URL with Sinatra: http://localhost:4567/token#access_token=7nuf5lgupiya8fd6rz4yzkzvwwo2ria&scope=user_read

我正在尝试使用Sinatra从以下URL捕获URL参数:http:// localhost:4567 / token#access_token = 7nuf5lgupiya8fd6rz4yzkzvwwo2ria&scope = user_read

I'm tried using a couple code blocks to do this:

我尝试使用几个代码块来执行此操作:

get '/token' do
    puts params['access_token']
end

and

get '/:token' do |token|
    puts token
end

and

get '/token#:token' do |token|
    puts token
end

However none of these work. In the first block I get an empty string, in the second block I get the string "token", and in the third block I get "Sinatra doesn't know this ditty".

然而,这些都不起作用。在第一个块中我得到一个空字符串,在第二个块中我得到字符串“token”,在第三个块中我得到“Sinatra不知道这个小曲”。

What would be the appopriate solution in this example?

在这个例子中,适用的解决方案是什么?

1 个解决方案

#1


1  

Is that url you wrote correct? I think it needs to be

你写的那个网址是否正确?我认为它需要

http://localhost:4567/token?access_token=7nuf5lgupiya8fd6rz4yzkzvwwo2ria&scope=user_read

With a ? instead of a # after /token. With that change, you should be able to access all the query parameters in the params hash.

有一个?而不是#after / token。通过该更改,您应该能够访问params哈希中的所有查询参数。

#1


1  

Is that url you wrote correct? I think it needs to be

你写的那个网址是否正确?我认为它需要

http://localhost:4567/token?access_token=7nuf5lgupiya8fd6rz4yzkzvwwo2ria&scope=user_read

With a ? instead of a # after /token. With that change, you should be able to access all the query parameters in the params hash.

有一个?而不是#after / token。通过该更改,您应该能够访问params哈希中的所有查询参数。