简体   繁体   中英

Request content from httpclient to WebApi changing between client / server

I'm working on a solution for authenticating WebApi requests with HMAc (Similar to this)

Part of this, looks at the outbound requests Content, and generates an MD5 hash of it (this is included as part of the overall hash of the message)

In one particular instance (a GET request), on my outbound requests, the value of .Content is null.

However, when it reaches the server side handler, there is a value in .Content

If I do a .ReadAsStringAsync() on the request.Content coming in to the handler, I can see it now looks like this:

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

Which, when generating an MD5 hash of the content, obviously isn't matching with my outbound request.

Any idea where the "content" has come from?
Can I prevent it from generating this?

EDIT This only seems to happen on GET requests

That looks to me like the output of Task.ToString(). You need to be looking at the result of the task. Either await it or access .Result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM