예제 #1
0
        public static async Task <string> SendPostRequestAsync(YifyMultiPartRequest request)
        {
            HttpClient client = null;

            if (PROXY != null)
            {
                client = new HttpClient(new HttpClientHandler()
                {
                    UseProxy = true, Proxy = PROXY
                });
            }
            else
            {
                client = new HttpClient();
            }

            MultipartFormDataContent content = new MultipartFormDataContent();

            foreach (var item in request.Data.Keys)
            {
                content.Add(new StringContent(request.Data[item.ToString()], Encoding.UTF8), item.ToString());
            }

            foreach (var item in request.Files)
            {
                var bcontent = new ByteArrayContent(item.Data, 0, item.Data.Length);
                bcontent.Headers.Add("Content-Disposition", "file; filename=\"" + item.Filename + "\"; name=" + item.FieldName);
                bcontent.Headers.Add("Content-Type", item.MimeType);
                bcontent.Headers.Add("Content-Transfer-Encoding", "binary");
                content.Add(bcontent);
            }

            HttpResponseMessage message = await client.PostAsync(request.Uri, content);

            byte[] data = await message.Content.ReadAsByteArrayAsync();

            return(Encoding.UTF8.GetString(data));
        }
예제 #2
0
        public static YifyMultiPartRequest GetEditUserSettingsRequest(
            string userKey,
            string applicationKey,
            string aboutText   = "",
            string newPassword = "",
            string avatarImage = "")
        {
            YifyMultiPartRequest request = new YifyMultiPartRequest();

            request.Uri = RequestUriHelper.EditUserSettigns.ToRequestUri(Base_URI, RESPONSE_TYPE);
            request.Data.Add("user_key", userKey);
            request.Data.Add("application_key", applicationKey);
            if (newPassword.HasValue())
            {
                request.Data.Add("new_password", newPassword);
            }
            if (aboutText.HasValue())
            {
                request.Data.Add("about_text", aboutText);
            }
            if (avatarImage.HasValue())
            {
                Image i = avatarImage.ToImage();

                if (i != null)
                {
                    YifyUploadFile file = new YifyUploadFile();
                    file.FieldName = "avatar_image";
                    file.Filename  = Path.GetFileName(avatarImage);
                    file.MimeType  = i.GetMimeType();
                    file.Data      = i.GetBytes();
                    request.Files.Add(file);
                }
            }
            return(request);
        }