惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
I
InfoQ
C
Check Point Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
Last Week in AI
Last Week in AI
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
B
Blog
T
The Blog of Author Tim Ferriss
H
Help Net Security
云风的 BLOG
云风的 BLOG

博客园 - Gary Zhang

Responses API 介绍与 deepseek-harness 应用分析报告 Human-in-the-Loop (HITL) 设计文档-学习笔记 MiniMind 从零训练 LLM — 详细学习笔记 C端产品的三个关键词和B端产品的一个关键词 人工智能相关概念 经济活动原理推导 使用Matlab对账期客户订单的逾期率进行预测 BizTalk RosettaNet 解决方案 - Gary BizTalk Visual Studio 各版本自动部署GAC命令 RosettaNet PIP 清单 BizTalk RosettaNet解决方案与项目调研 ChatGPT可能的影响与机会 使用Google Bigquery快速用SQL查询Excel数据 Azure logic App 构建低成本EDI解决方案(英文) 从 BizTalk 跟踪数据库中清除数据 自助批量下载Confluence文档内容 Elsa 工作流引擎 Hello World Azure 升级订阅服务及服务区别 MIME 消息 BizTalk性能优化配置(建议) Azure Logic APP 与 EDIFACT/X12/RosettaNet/AS2解决方案概述 BizTalk 安装管理 API
存储HTTP请求Body部分到文件中
Gary Zhang · 2023-12-14 · via 博客园 - Gary Zhang

代码

using System;
using System.IO;
using System.Web;

public class RequestLoggerModule : IHttpModule
{
    private const string LogFolderPath = @"C:\Gary\Log\"; // 替换为实际的日志文件夹路径

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

    public void Dispose()
    {
    }

    private void OnBeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpRequest request = application.Context.Request;

        // 读取请求内容
        using (StreamReader reader = new StreamReader(request.InputStream))
        {
            string requestBody = reader.ReadToEnd();

            // 在这里,将请求内容写入到文件
            LogRequest(requestBody);
        }
    }

    private void LogRequest(string content)
    {
        // 构造日志文件路径
        string logFilePath = Path.Combine(LogFolderPath, $"RequestLog_{DateTime.Now:yyyyMMdd_HHmmssfff}.txt");

        // 写入请求内容到文件
        File.WriteAllText(logFilePath, content);
    }
}

IIS配置

需要将DLL文件拷贝到网站文件目录的bin文件夹下面

	  <httpModules>
		  <add name="RequestLoggerModule" type="RequestLoggerModule" />
	  </httpModules>