Ejemplo n.º 1
0
        public async Task <List <Post_return> > Post(Post_message_class data, String request)
        {
            var response = await httpClient.PostAsJsonAsync(request, data);

            response.EnsureSuccessStatusCode();
            var json = await response.Content.ReadAsStringAsync();

            var check = JsonConvert.DeserializeObject <List <Post_check> >(json);
            List <Post_return> content;

            if (check[0].Task == "false")
            {
                Console.WriteLine(check[0].Content);
                content = JsonConvert.DeserializeObject <List <Post_return> >("[]");
            }
            else
            {
                content = JsonConvert.DeserializeObject <List <Post_return> >(check[0].Content);
            }
            return(content);
        }
Ejemplo n.º 2
0
        async public Task <bool> UploadFile(Post_message_class data, string FilePath)
        {
            var filetype = MimeTypes.GetMimeType(Path.GetFileName(FilePath));

            byte[] FileData = System.IO.File.ReadAllBytes(FilePath);

            var requestContent = new MultipartFormDataContent();

            var FileContent = new ByteArrayContent(FileData);

            FileContent.Headers.ContentType =
                MediaTypeHeaderValue.Parse(filetype);

            requestContent.Add(FileContent, "file", Path.GetFileName(FilePath));

            var response = await httpClient.PostAsync(server + "upload", requestContent);

            try {
                response.EnsureSuccessStatusCode();
            } catch {
                Console.WriteLine("file to big");
                return(false);
            }

            data.File_id = await response.Content.ReadAsStringAsync();

            data.File_name = Path.GetFileName(FilePath);

            if (data.File_id == "fail")
            {
                Console.WriteLine("server error");
                return(false);
            }

            await Post(data, server + "addfiletochat");

            return(true);
        }