【问题标题】:Request content from httpclient to WebApi changing between client / server请求内容从 httpclient 到 WebApi 在客户端/服务器之间更改
【发布时间】:2023-03-27 01:28:01
【问题描述】:

我正在研究一种使用 HMAc 验证 WebApi 请求的解决方案(与此类似)

其中的一部分,查看出站请求内容,并生成它的 MD5 哈希 (这包含在消息的整体哈希中)

在一个特定实例(GET 请求)中,在我的出站请求中,.Content 的值为 null。

但是,当它到达服务器端处理程序时,.Content 中有一个值

如果我对进入处理程序的 request.Content 执行 .ReadAsStringAsync(),我可以看到它现在看起来像这样:

Id = 1, Status = RanToCompletion, Method = "{null}", Result = ""
AsyncState: null
CancellationPending: false
CreationOptions: None
Exception: null
Id: 1
Result: ""
Status: RanToCompletion

在生成内容的 MD5 哈希时,显然与我的出站请求不匹配。

知道“内容”的来源吗?
我可以防止它产生这种情况吗?

编辑 这似乎只发生在 GET 请求上

【问题讨论】:

    标签: c# asp.net-web-api dotnet-httpclient system.net.httpwebrequest


    【解决方案1】:

    在我看来,这就像 Task.ToString() 的输出。您需要查看任务的结果。等待它或访问 .Result。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-02
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2018-01-19
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      相关资源
      最近更新 更多