5

Where did my request body data go? | Alan Coates – Sitecore/.NET blog

 2 years ago
source link: https://blog.coates.dk/2021/09/30/where-did-my-request-body-data-go/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Where did my request body data go?

Problem

The solution had several API controllers (see image above) that expected data to be posted in the body. Then for no reason the body data was null, and therefore the controller started throwing argument null exceptions, and the front end of course stopped working.

The issue was caused by a new custom HttpRequestProcessor (see image below), which was called in the httpRequestBegin pipeline.

It needed the data from the request body, for some reason the setting the position back to 0, did not work?

Therefore the controller got null instead of the data contained in the body.

Solution

Therefore it was necessary to copy the stream contents into a memory stream, read the data from that stream, then deserialize the class. See the solution below.

I hope this helps, and this issue was found Sitecore 8, with a lot of customization, patches, code and modifications over the past 16 years.

This entry was posted in Pipeline, Sitecore and tagged MemoryStream, Pipeline, Request Body on September 30, 2021.

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK