question

AmyZ-5475 avatar image
0 Votes"
AmyZ-5475 asked MayankBargali-MSFT commented

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

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
image.png (42.3 KiB)
image.png (58.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT commented

@AmyZ-5475 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


image.png (15.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MayankBargali-MSFT thank you for the hint, I just realize hovering over the size on postman can get more information. :)
I've dumped context.Request.Headers and find Content-Length might be what I want. But it seems Content-Length is the same as context.Request.Body.Length , same result in Postman.

According to this post, it seems only body size(Content-Length) is what I can get from request/response.

81090-image.png


0 Votes 0 ·
image.png (47.0 KiB)

@AmyZ-5475 Thanks for your response. Glad the answer helped and you were able to find the solution. Feel free to 'Accept as answer' if it helped so that it can help others in the community looking for help on similar topics.

0 Votes 0 ·