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

            if (data is Binary)
            {
                var bin = (Binary)data;
                body = bin.Content;
                // This is done by the caller after the OnBeforeRequest is called so that other properties
                // can be set before the content is committed
                // request.WriteBody(CompressRequestBody, bin.Content);
                request.ContentType = bin.ContentType;
            }
            else
            {
                body = format == ResourceFormat.Xml ?
                       FhirSerializer.SerializeToXmlBytes(data, summary: Fhir.Rest.SummaryType.False) :
                       FhirSerializer.SerializeToJsonBytes(data, summary: Fhir.Rest.SummaryType.False);

                // This is done by the caller after the OnBeforeRequest is called so that other properties
                // can be set before the content is committed
                // request.WriteBody(CompressRequestBody, body);
                request.ContentType = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }
        }
Esempio n. 2
0
        private static void SetBodyAndContentType(HttpWebRequest request, Resource payload, ResourceFormat format, bool CompressRequestBody, out byte[] body)
        {
            if (payload == null)
            {
                throw Error.ArgumentNull(nameof(payload));
            }

            if (payload is Binary)
            {
                var bin = (Binary)payload;
                body = bin.Content;
                request.ContentType = bin.ContentType;
            }
            else
            {
                body = format == ResourceFormat.Xml ?
                       FhirSerializer.SerializeToXmlBytes(payload, summary: Hl7.Fhir.Rest.SummaryType.False) :
                       FhirSerializer.SerializeToJsonBytes(payload, summary: Hl7.Fhir.Rest.SummaryType.False);

                request.ContentType = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }
        }
        private static void setBodyAndContentType(HttpWebRequest request, Resource data, ResourceFormat format)
        {
            if (data == null)
            {
                throw Error.ArgumentNull("data");
            }

            if (data is Binary)
            {
                var bin = (Binary)data;
                request.WriteBody(bin.Content);
                request.ContentType = bin.ContentType;
            }
            else
            {
                var 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);
            }
        }