Exemple #1
0
        public async Task PostCommentAsync(string comment)
        {
            var requestBody = $"commenttext={WebUtility.UrlEncode(comment)}&postcomment=Post+Comment";



            var httpClient = new Windows.Web.Http.HttpClient(new HttpBaseProtocolFilter());
            var message    = new Windows.Web.Http.HttpRequestMessage(
                new Windows.Web.Http.HttpMethod("POST"),
                new Uri(this.Link))
            {
                Content = new HttpStringContent(requestBody)
            };

            message.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded");
            message.Headers["Cookie"]           = await ExClient.GetExCookieAsync("");

            var response = await httpClient.SendRequestAsync(message);

            var responseString = await response.Content.ReadAsStringAsync();


            // Handle error page returned from server
            if (true) // sccuess
            {
                // Refresh the commenet list
                HtmlDocument htmlDocument = new HtmlDocument()
                {
                    OptionFixNestedTags = true
                };
                htmlDocument.LoadHtml(responseString);
                this.Comments.Clear();
                HtmlNodeCollection commentNodes = htmlDocument.DocumentNode.SelectNodes("//div[@class='c1']");
                if (commentNodes != null)
                {
                    foreach (var node in commentNodes)
                    {
                        this.Comments.Add(ExComment.FromNode(node));
                    }
                }
            }
        }