We develop an application for several platforms, we create the entire platform-independent part using PCL, trying to achieve the maximum level of component reuse. For communications with the server, the HttpWebRequest class is used which implements all the necessary functionality from the transport layer.request.Headers[HttpRequestHeader.IfModifiedSince] = timeStamp.ToString(); namespace System.Net { public static class NetExtensions { private static Action<HttpWebRequest, DateTime> _setIfMofifiedSince; public static void SetIfModifiedSince(this HttpWebRequest request, DateTime value) { Guard.NotNull(request); if (_setIfMofifiedSince != null) { _setIfMofifiedSince(request, value); return; } try { request.Headers[HttpRequestHeader.IfModifiedSince] = value.ToString(); return; } // ReSharper disable once EmptyGeneralCatchClause catch { } var property = request.GetType().GetRuntimeProperty("IfModifiedSince"); if (property != null && property.CanWrite) { var method = property.SetMethod; if (method != null) { _setIfMofifiedSince = (Action<HttpWebRequest, DateTime>)method.CreateDelegate(typeof(Action<HttpWebRequest, DateTime>)); } } if (_setIfMofifiedSince == null) { throw new Exception("Unable to set IfModifiedSince"); } _setIfMofifiedSince(request, value); } } } request.SetIfModifiedSince(timeStamp); Source: https://habr.com/ru/post/219809/
All Articles