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); }
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; }