【问题标题】:Get everything after the root domain name from an HTTP request从 HTTP 请求中获取根域名之后的所有内容
【发布时间】:2015-02-14 03:46:41
【问题描述】:

是否可以使用 Java 从 HTTP 请求中获取根域名之后的所有内容?

所以如果请求的 url 是 http://example.com/my-path 那么我想得到 my-path 的值

我正在使用 PlayFramework,所以如果有一个名为“Path”的标题或类似的东西,它应该更容易获得它:

String path = request.headers.get("path");

但是这个页面表明这样的事情不存在:

https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

如果有不同的解决方案来获得相同的结果,那也将不胜感激。如果可能的话,它也会为这个问题提供一个解决方案:

 http://stackoverflow.com/questions/28503129/redirect-example-com-to-www-example-com-in-playframework-1-2-x

【问题讨论】:

  • 理想情况下只是根域之后的路径,但我想我也可以去掉域
  • 这能回答你的问题吗?

标签: java http playframework http-headers


【解决方案1】:

要获取域之后的所有内容,请使用uri

String path = request.uri();

或者如果你想切掉查询字符串参数,使用path

String path = request.path();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-18
    • 2019-02-15
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 2012-03-14
    • 2011-07-11
    • 2019-09-27
    相关资源
    最近更新 更多