我正在使用 .net 4.5 框架。我能够使用 RequestTelemetry 读取登录应用程序洞察的请求。编写以下正在运行的代码。
var requestTelemetry = telemetry as RequestTelemetry;
if (requestTelemetry == null) return;
var context = HttpContext.Current;
if (context == null) return;
if (context.Request != null)
{
if ((context.Request.HttpMethod == HttpMethod.Post.ToString()
|| context.Request.HttpMethod == HttpMethod.Put.ToString()) && WhitelistCheck(context.Request.RawUrl))
{
using (var reader = new StreamReader(context.Request.InputStream))
{
string requestPayload = reader.ReadToEnd();
if (!telemetry.Context.Properties.ContainsKey(Request_Payload))
{
// TO DO: Don't log Personally identifiable information (PII)
requestTelemetry.Properties.Add(Request_Payload, requestPayload);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
要读取响应,我遇到了问题,即 context.Response.OutputStream 是只写的,我们无法直接读取它。在 core 中,我们有 response.body 属性,但在 .net 4.5 …