2014-06-23 29 views
0

我做了一個記錄Web請求的IHttpModule。它記錄POST請求很好。但是對於GET請求,長度似乎總是爲零。有沒有辦法獲得GET請求的長度?使用IHttpModule記錄請求長度

public void Init(HttpApplication context) 
    { 
     context.BeginRequest += ContextBeginRequest; 
    } 

    private void ContextBeginRequest(object sender, EventArgs e) 
    { 
      string url = app.Request.RequestContext.HttpContext.Request.Url.ToString(); 
      string requestType = app.Request.RequestContext.HttpContext.Request.RequestType; 
      long requestLength = app.Request.InputStream.Length; 
      Log(url, requestType, requestLength); 
    } 

回答

2

GET請求通常不具有消息體,因此,該Content-Length將爲零。

+0

感謝Rodrick,但我如何獲得整個請求的長度? (所有HTTP頭的東西) – Fidel

+0

@Fidel我現在無法測試這個,但你可以嘗試直接迭代服務器變量。我會從ALL_RAW開始。 –

+0

感謝Rodrick,是的ServerVariables [「ALL_RAW」]變得非常接近。但它不包含HTTP請求的第一行。 – Fidel