private static void setBodyAndContentType(HttpWebRequest request, Resource data, ResourceFormat format, out byte[] body)
        {
            if (data == null) throw Error.ArgumentNull("data");

            if (data is Binary)
            {
                var bin = (Binary)data;
                body = bin.Content;
                request.WriteBody(bin.Content);
                request.ContentType = bin.ContentType;
            }
            else
            {
                body = format == ResourceFormat.Xml ?
                    FhirSerializer.SerializeToXmlBytes(data, summary: false) :
                    FhirSerializer.SerializeToJsonBytes(data, summary: false);

                request.WriteBody(body);
                request.ContentType = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }
        }