Beispiel #1
0
        public async Task <bool> Post(byte[] requestBody, string imageFileName)
        {
            var content  = GetContent(requestBody, imageFileName);
            var response = await RC.PostContent(Endpoint(false), content);

            return(true);
        }
Beispiel #2
0
        public Task <FaxResponse> Post(object requestBody, IEnumerable <Attachment> attachments)
        {
            var multipartFormDataContent = new MultipartFormDataContent();

            multipartFormDataContent.Headers.ContentType.MediaType = "multipart/form-data";

            var jsonBody        = JsonConvert.SerializeObject(requestBody, RestClient.jsonSerializerSettings);
            var jsonFileContent = new ByteArrayContent(Encoding.UTF8.GetBytes(jsonBody));

            jsonFileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                Name     = "json",
                FileName = "request.json"
            };
            jsonFileContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            multipartFormDataContent.Add(jsonFileContent);

            foreach (var attachment in attachments)
            {
                var fileContent = new ByteArrayContent(attachment.bytes);
                fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name     = "attachment",
                    FileName = attachment.fileName
                };
                fileContent.Headers.ContentType = new MediaTypeHeaderValue(attachment.contentType);
                multipartFormDataContent.Add(fileContent);
            }

            return(RC.PostContent(Endpoint(false), multipartFormDataContent).ReceiveJson <FaxResponse>());
        }
Beispiel #3
0
        public Task <MessageInfo> Post(object requestBody, IEnumerable <Attachment> attachments)
        {
            var multipartFormDataContent = new MultipartFormDataContent();

            multipartFormDataContent.Headers.ContentType.CharSet   = "UTF-8";
            multipartFormDataContent.Headers.ContentType.MediaType = "multipart/mixed";
            var jsonBody = JsonConvert.SerializeObject(requestBody, RestClient.jsonSerializerSettings);

            multipartFormDataContent.Add(new StringContent(jsonBody, Encoding.UTF8, "application/json"));
            foreach (var attachment in attachments)
            {
                var fileContent = new ByteArrayContent(attachment.bytes);
                fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = attachment.fileName
                };
                fileContent.Headers.ContentType = new MediaTypeHeaderValue(attachment.contentType);
                multipartFormDataContent.Add(fileContent);
            }
            return(RC.PostContent(Endpoint(false), multipartFormDataContent).ReceiveJson <MessageInfo>());
        }