public async Task <CommentInformation> DeleteComment(CommentInformation info, bool both) { // HTTP 요청에 딜레이를 주어 서버 오류 방지 int delay = 50; GallogCommentDeleteParameter delParams = null; try { delParams = await this.GetDeleteCommentInfoAsync(info.DeleteUrl); } catch (Exception e) { info.IsGalleryDeleted = false; info.IsGallogDeleted = false; info.DeleteMessage = e.Message; return(info); } info.GalleryDeleteParameter = new GalleryCommentDeleteParameter() { GalleryId = delParams.GalleryId, ArticleId = delParams.ArticleId, CommentId = delParams.CommentId }; info.GallogDeleteParameter = delParams; await Task.Delay(delay); return(await DeleteComment(info, true, both)); }
internal static async Task <GallogCommentDeleteParameter> GetDeleteGallogCommentParameterAsync(string pageHtml) { return(await Task.Run(() => { GallogCommentDeleteParameter newParams = new GallogCommentDeleteParameter(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageHtml); HtmlNode parentNode = doc.GetElementbyId("dTp").ParentNode; HtmlNode idNode = parentNode.SelectSingleNode(".//input[@name='id']"); HtmlNode cidNode = parentNode.SelectSingleNode(".//input[@name='cid']"); HtmlNode artNode = parentNode.SelectSingleNode(".//input[@name='no']"); HtmlNode cNode = parentNode.SelectSingleNode(".//input[@name='c_no']"); HtmlNode logNode = parentNode.SelectSingleNode(".//input[@name='logNo']"); int inputCnt = doc.DocumentNode.Descendants("input").Count(); HtmlNode randomKeyNode = doc.DocumentNode.SelectSingleNode("//input[" + (inputCnt - 1) + "]"); newParams.GalleryId = idNode.Attributes["value"].Value; newParams.GalleryNo = cidNode.Attributes["value"].Value; newParams.ArticleId = artNode.Attributes["value"].Value; newParams.CommentId = cNode.Attributes["value"].Value; newParams.LogNo = logNode.Attributes["value"].Value; newParams.AdditionalParameter.Push(randomKeyNode.Attributes["name"].Value, randomKeyNode.Attributes["value"].Value); return newParams; })); }
private async Task <GallogCommentDeleteParameter> GetDeleteCommentInfoAsync(string url) { string galHtml = await GetDeleteGallogCommentPageAsync(url, user_id); GallogCommentDeleteParameter retParams = await HtmlParser.GetDeleteGallogCommentParameterAsync(galHtml); retParams.UserId = user_id; return(retParams); }
private async Task <DeleteResult> PostDeleteGallogCommentAsync(GallogCommentDeleteParameter param, int delay) { string reqURL = _gallogURL + "/inc/_deleteRepOk.php"; string referer = _gallogURL + "/inc/_deleteLogRep.php?gid=" + param.UserId + "&cid=" + param.GalleryNo + "&id=" + param.GalleryId + "&no=" + param.ArticleId + "&logNo=" + param.LogNo + "&rpage="; using (HttpClientHandler handler = new HttpClientHandler() { CookieContainer = cookies }) using (HttpClient client = new HttpClient(handler)) { client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString); client.DefaultRequestHeaders.Referrer = new Uri(referer); client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent); client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout); string reqData = "rb=&dTp=1&gid=" + param.UserId + "&cid=" + param.GalleryNo + "&page=&pno=" + "&no=" + param.ArticleId + "&c_no=" + param.CommentId + "&logNo=" + param.LogNo + "&id=" + param.GalleryId + "&nate=&"; reqData += param.AdditionalParameter.ToString(); using (HttpResponseMessage res = await client.PostAsync(reqURL, new StringContent(reqData, Encoding.UTF8, "application/x-www-form-urlencoded"))) { res.EnsureSuccessStatusCode(); using (HttpContent content = res.Content) { string result = await content.ReadAsStringAsync(); // 성공 if (result.Contains("GidMgr.resetGalleryData(2);")) { return(new DeleteResult(true, "")); } else { return(new DeleteResult(false, "알 수 없는 오류입니다.")); } } } } }