コード例 #1
0
ファイル: Request.cs プロジェクト: prearrangedchaos/Ramone
        public Request Body(object body)
        {
            ICodecManager codecManager = Session.Service.CodecManager;

            if (BodyContentType == null)
            {
                BodyContentType = Session.DefaultRequestMediaType;
            }

            if (body != null)
            {
                MediaTypeWriterRegistration writer = codecManager.GetWriter(body.GetType(), BodyContentType ?? MediaType.Wildcard);
                if (BodyContentType == null)
                {
                    BodyContentType = writer.MediaType;
                }
                BodyCodec = writer.Codec;
            }
            else if (BodyContentType == null)
            {
                BodyContentType = MediaType.ApplicationFormUrlEncoded;
            }

            if (BodyContentType.Matches("multipart/form-data"))
            {
                BodyBoundary = Guid.NewGuid().ToString();
            }

            BodyData = body;

            return(this);
        }
コード例 #2
0
        protected void SetBody(object body)
        {
            ICodecManager codecManager = Session.Service.CodecManager;

            if (BodyContentType == null)
            {
                BodyContentType = Session.DefaultRequestMediaType;
            }

            if (body != null)
            {
                MediaTypeWriterRegistration writer = codecManager.GetWriter(body.GetType(), BodyContentType ?? MediaType.Wildcard);
                if (BodyContentType == null)
                {
                    BodyContentType = writer.MediaType;
                }
                if (BodyContentType.IsAnyWildcard)
                {
                    throw new InvalidOperationException($"Wildcard media type {BodyContentType} is not a valid content type.");
                }
                BodyCodec = writer.Codec;
            }
            else if (BodyContentType == null)
            {
                BodyContentType = MediaType.ApplicationFormUrlEncoded;
            }

            if (BodyContentType.Matches("multipart/form-data"))
            {
                BodyBoundary = Guid.NewGuid().ToString();
            }

            BodyData = body;
        }