ASP.NET C#でリクエストの中身(HeaderとBody)をファイルに書き出す

C#に詳しい人からすれば簡単だと思いますが、忘れてしまいそうなので、メモ

        System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream);
        string str = reader.ReadToEnd();
        System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\data\dump.txt", true, System.Text.Encoding.ASCII);
        sw.Write(str);
        sw.Close();

        string result = "";
        int loop1, loop2;
        NameValueCollection coll;
        coll = Request.Headers;
        String[] arr = coll.AllKeys;
        for (loop1 = 0; loop1 < arr.Length; loop1++)
        {
            result += arr[loop1];
            String[] arr2 = coll.GetValues(arr[loop1]);
            for (loop2 = 0; loop2 < arr2.Length; loop2++)
            {
                result += arr2[loop2] + ",";
            }
            result += "...\n";
        }
        System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\data\header.txt", true, System.Text.Encoding.ASCII);
        sw.Write(result);
        sw.Close();