【问题标题】:how to get the server name from a http response如何从 http 响应中获取服务器名称
【发布时间】:2013-07-24 11:28:37
【问题描述】:

我想知道响应来自哪个服务器。

使用 HttpMethod,我正在阅读 HttpStatus、Method-Name 和其他内容。但是我如何知道响应服务器呢?

感谢您的帮助。

编辑:

boolean checkR(HttpMethod method){
    if (method.getStatusCode() == HttpStatus.SC_OK) {
        return true;
    } else {
        System.out.println("HTTP response was " + method.getStatusLine().toString());
        return false;
    } 
  }

我想返回如下内容:“HTTP 响应是”+method.getStatusLine().toString())+“来自服务器”+??? Server-name ??;

【问题讨论】:

  • 您的代码可能会有所帮助

标签: java http http-method


【解决方案1】:

简单的答案是您不能,因为远程服务器地址不是 HTTP 响应标头的一部分。

虽然字段名称为 HOST,但它是您的请求标头的一部分。

这些是 HTTP 响应中的一些标头字段:

ETag
Content-Length
Expires
Last-Modified
Connection
X-Powered-By
Server
Pragma
Cache-Control
Date
Vary
Keep-Alive
Content-Type
Accept-Ranges

See this link for complete list

【讨论】:

    猜你喜欢
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    相关资源
    最近更新 更多