다음은 HTTP POST 요청 데이터를 기록하는 데 사용하는 사용자 정의 HTTP 모듈의 코드입니다.
using System;
using System.Web;
namespace MySolution.HttpModules
{
public class HttpPOSTLogger : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
private void context_BeginRequest(object sender, EventArgs e)
{
if (sender != null && sender is HttpApplication)
{
var request = (sender as HttpApplication).Request;
var response = (sender as HttpApplication).Response;
if (request != null && response != null && request.HttpMethod.ToUpper() == "POST")
{
var body = HttpUtility.UrlDecode(request.Form.ToString());
if (!string.IsNullOrWhiteSpace(body))
response.AppendToLog(body);
}
}
}
}
}
응용 프로그램의 web.config에 등록하는 것을 잊지 마십시오. 적용 모듈 전에 IIS 클래식 모델
<system.web>
<httpModules>
<add name="HttpPOSTLogger" type="MySolution.HttpModules.HttpPOSTLogger, MySolution.HttpModules"/>
</httpModules>
</system.web>
IIS 로그의 IIS 통합 모델
<system.webServer>
<modules>
<add name="HttpPOSTLogger" type="MySolution.HttpModules.HttpPOSTLogger, MySolution.HttpModules" />
</modules>
</system.webServer>
사용 system.web 섹션
사용의 system.webServer 섹션 :
::1, -, 10/31/2017, 10:53:20, W3SVC1, machine-name, ::1, 5, 681, 662, 200, 0, POST, /MySolution/MyService.svc/MyMethod, -,
IIS 로그 적용 후 :
::1, -, 10/31/2017, 10:53:20, W3SVC1, machine-name, ::1, 5, 681, 662, 200, 0, POST, /MySolution/MyService.svc/MyMethod, {"model":{"Platform":"Mobile","EntityID":"420003"}},
전체 기사 : 당신이 브라우저에서 조회하는 경우
https://www.codeproject.com/Tips/1213108/HttpModule-for-logging-HTTP-POST-data-in-IIS-Log
피들러가 작동합니다. 내 응용 프로그램 내에서 웹 서비스 호출이 작동하지 않습니다. –
@ Mr Greieves, 약간의 추가 작업이 필요하지만 웹 서비스 호출에 대한 프록시 설정을 수동으로 구성 할 수 있습니다. –