diff --git a/src/Foundation/NSUrlSessionHandler.cs b/src/Foundation/NSUrlSessionHandler.cs index acb7ccd687..93e6eb3b4a 100644 --- a/src/Foundation/NSUrlSessionHandler.cs +++ b/src/Foundation/NSUrlSessionHandler.cs @@ -857,7 +857,13 @@ namespace Foundation { [Preserve (Conditional = true)] public override void WillCacheResponse (NSUrlSession session, NSUrlSessionDataTask dataTask, NSCachedUrlResponse proposedResponse, Action completionHandler) { - completionHandler (sessionHandler.DisableCaching ? null! : proposedResponse); + var inflight = GetInflightData (dataTask); + + if (inflight is null) + return; + // apple caches post request with a body, which should not happen. https://github.com/xamarin/maccore/issues/2571 + var disableCache = sessionHandler.DisableCaching || (inflight.Request.Method == HttpMethod.Post && inflight.Request.Content is not null); + completionHandler (disableCache ? null! : proposedResponse); } [Preserve (Conditional = true)]