【发布时间】:2011-09-20 12:21:37
【问题描述】:
一些移动网关正在将自定义标头传递到我的网站。这些标头以各种格式传递,有时是 x-msisdn,有时是 x-up-calling-line-id 等。如何记录以我的自定义日志格式传递的所有标头?
【问题讨论】:
-
您不能仅使用 Apache 和 mod_log_config 来执行此操作。您可以使用 mod_security
一些移动网关正在将自定义标头传递到我的网站。这些标头以各种格式传递,有时是 x-msisdn,有时是 x-up-calling-line-id 等。如何记录以我的自定义日志格式传递的所有标头?
【问题讨论】:
通过 Apache HTTPD 我不确定如何记录 所有 标头 - 只知道如何记录您知道的一个标头。
使用标准 Apache httpd 模块 mod_log_config,您可以在 CustomLog 指令中指定以下选项。
%{Foobar}i Foobar 的内容:发送到服务器的请求中的标题行。其他模块(例如 mod_headers)所做的更改会影响这一点。
但是您可以在 jsp 中执行此操作(如果这是您偶然使用的)
<!-- method used to send request
<%= request.getMethod() %>
URI of the request
<%= request.getRequestURI() %>
<%
/*This method returns an enumeration of all the header names this
request contains.*/
java.util.Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String hname = (String)names.nextElement();
%>
<%= hname %>
<%= request.getHeader(hname) %>
<%
}
%>
--!>
【讨论】:
您也可以通过嗅探网络接口来执行此操作。
Wireshark 有 tshark (apt-get install tshark) tshark 'tcp 端口 80 和 (((ip[2:2] - ((ip[0]&0xf)>2)) != 0)' -R 'http.request.method == "GET" || http.request.method == "HEAD"'
(以上来自http://andy.wordpress.com/2008/07/10/sniffing-http/tshark 是 tethereal 的新名称)
【讨论】: