How to get the request and response size in APIM policy ?

Amy Z 296 Reputation points
2021-03-23T09:08:03.597+00:00

Hi, we want to log request and response size for further analysis. Already studied this post to get some hint.
We use context.Request.Body.Length in the policy to get the number.
After comparing the policy logged value, APIM built-in value and Postman, we find the numbers from policy seems incorrect.
( yellow values are from policy )

80490-image.png

80510-image.png
Not sure why this happens, or we use wrong property ?

Need your advice, thank you

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,172 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,531 Reputation points
    2021-03-23T09:35:25.807+00:00

    @Amy Z The postman would be having the total size (body + header). If you hover over the size you will find the body and header size.
    When you use context.Request.Body.Length then it will be the request body length not the total size of the request. If you want the total size then you can add the header and body length.

    80586-image.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.