请求之间有什么区别?env(“REQUEST_URI”)和request.env(“REQUEST_PATH”)?

时间:2022-02-16 13:21:18

What's the difference between request.env['REQUEST_URI'] and request.env['REQUEST_PATH'] in Rails? They always seem to contain the same value.

请求之间有什么区别?env(“REQUEST_URI”)和请求。Rails env(“REQUEST_PATH”)?它们似乎总是包含相同的值。

2 个解决方案

#1


26  

I believe delroth is correct about the distinction, however in almost all cases it's better to use the methods in Request instead of directly accessing the environment variables.

我认为delroth的区分是正确的,但是在几乎所有的情况下,最好使用Request中的方法,而不是直接访问环境变量。

request.request_uri returns the requested url including the query string and without the domain.

请求。request_uri返回请求的url,包括查询字符串,但不返回域。

request.path returns the path of the request without the query string, domain and any relative root (if your app runs from a directory other than root).

请求。path返回请求的路径,没有查询字符串、域和任何相关根(如果您的应用程序从根以外的目录运行)。

See the Rails API for ActionDispatch::Request to see other helpful methods.

查看ActionDispatch::请求的Rails API以查看其他有用的方法。

#2


9  

I believe REQUEST_URI also contains query GET arguments, whereas REQUEST_PATH don't. But I'm not completely sure of that.

我认为REQUEST_URI还包含查询GET参数,而REQUEST_PATH不包含。但我不太确定。

For example :

例如:

  • REQUEST_URI = /foo/bar/?x=1&y=2
  • REQUEST_URI = / foo / bar / ? x = 1 y = 2
  • REQUEST_PATH = /foo/bar/
  • REQUEST_PATH = / foo / bar /

#1


26  

I believe delroth is correct about the distinction, however in almost all cases it's better to use the methods in Request instead of directly accessing the environment variables.

我认为delroth的区分是正确的,但是在几乎所有的情况下,最好使用Request中的方法,而不是直接访问环境变量。

request.request_uri returns the requested url including the query string and without the domain.

请求。request_uri返回请求的url,包括查询字符串,但不返回域。

request.path returns the path of the request without the query string, domain and any relative root (if your app runs from a directory other than root).

请求。path返回请求的路径,没有查询字符串、域和任何相关根(如果您的应用程序从根以外的目录运行)。

See the Rails API for ActionDispatch::Request to see other helpful methods.

查看ActionDispatch::请求的Rails API以查看其他有用的方法。

#2


9  

I believe REQUEST_URI also contains query GET arguments, whereas REQUEST_PATH don't. But I'm not completely sure of that.

我认为REQUEST_URI还包含查询GET参数,而REQUEST_PATH不包含。但我不太确定。

For example :

例如:

  • REQUEST_URI = /foo/bar/?x=1&y=2
  • REQUEST_URI = / foo / bar / ? x = 1 y = 2
  • REQUEST_PATH = /foo/bar/
  • REQUEST_PATH = / foo / bar /