Ejemplo n.º 1
0
        private async Task <DeleteResult> PostDeleteMinorGalleryFlowArticleAsync(GalleryArticleDeleteParameter delParam, string key)
        {
            string pageHtml = await GetDeleteGalleryArticlePageAsync(delParam.GalleryId, delParam.ArticleID, key, GalleryType.Minor);

            Tuple <ParameterStorage, string> parseResult;
            ParameterStorage delete_Params = null;

            try
            {
                parseResult = await HtmlParser.GetDeleteFlowArticleParameterAsync(pageHtml, GalleryType.Minor);
            }
            catch (Exception e)
            {
                return(new DeleteResult(false, e.Message));
            }

            delete_Params = parseResult.Item1;

            string reqURL  = _galleryURL + "/mgallery/forms/delete_submit";
            string referer = _galleryURL + "/mgallery/board/delete/?id=" + delParam.GalleryId + "&no=" + delParam.ArticleID + "&key=" + key;

            using (HttpClientHandler handler = new HttpClientHandler()
            {
                CookieContainer = cookies
            })
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString);
                    client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                    client.DefaultRequestHeaders.Referrer = new Uri(referer);
                    client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);
                    client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout);

                    string reqData = delete_Params.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.StartsWith("true||" + delParam.GalleryId))
                            {
                                return(new DeleteResult(true, ""));
                            }
                            else if (result == "false||비밀번호 인증에 실패하였습니다. 다시 시도해주세요" ||
                                     result == "false|| 비밀번호가 맞지 않습니다. 다시 시도해주세요" ||
                                     result == "false||비밀번호가 잘못되었습니다. 다시 시도해주세요")
                            {
                                return(new DeleteResult(false, "비밀번호가 다릅니다."));
                            }
                            else
                            {
                                return(new DeleteResult(false, "알 수 없는 오류입니다."));
                            }
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        private async Task <DeleteResult> PostDeleteGalleryFlowArticleAsync(GalleryArticleDeleteParameter delParam, GalleryType gallType, int delay)
        {
            string pageHtml = await GetDeleteGalleryArticlePageAsync(delParam.GalleryId, delParam.ArticleID, null, gallType);

            Tuple <ParameterStorage, string> parseResult;
            ParameterStorage delete_Params  = null;
            string           lately_gallery = null;

            try
            {
                parseResult = await HtmlParser.GetDeleteFlowArticleParameterAsync(pageHtml, gallType);
            }
            catch (Exception e)
            {
                return(new DeleteResult(false, e.Message));
            }

            delete_Params  = parseResult.Item1;
            lately_gallery = parseResult.Item2;

            if (gallType == GalleryType.Normal)
            {
                cookies.Add(new Cookie("lately_cookie", HttpUtility.UrlEncode(lately_gallery))
                {
                    Domain = "dcinside.com"
                });
            }

            await Task.Delay(delay);

            string reqURL  = null;
            string referer = null;

            if (gallType == GalleryType.Normal)
            {
                reqURL  = _galleryURL + "/forms/delete_password_submit";
                referer = _galleryURL + "/board/delete/?id=" + delParam.GalleryId + "&no=" + delParam.ArticleID;
            }
            else if (gallType == GalleryType.Minor)
            {
                reqURL  = _galleryURL + "/mgallery/forms/delete_password_submit";
                referer = _galleryURL + "/mgallery/board/delete/?id=" + delParam.GalleryId + "&no=" + delParam.ArticleID;
            }

            if (reqURL == null || referer == null)
            {
                throw new Exception("예상치 못한 갤러리 형식입니다.");
            }

            using (HttpClientHandler handler = new HttpClientHandler()
            {
                CookieContainer = cookies
            })
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.ParseAdd(_defaultAcceptString);
                    client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                    client.DefaultRequestHeaders.Referrer = new Uri(referer);
                    client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);
                    client.Timeout = new TimeSpan(0, 0, 0, 0, _defaultTimeout);

                    string reqData = delete_Params.ToString();
                    reqData += "&password="******"application/x-www-form-urlencoded")))
                    {
                        res.EnsureSuccessStatusCode();

                        using (HttpContent content = res.Content)
                        {
                            string result = await content.ReadAsStringAsync();

                            if (result.StartsWith("true||"))
                            {
                                if (gallType == GalleryType.Normal)
                                {
                                    return(new DeleteResult(true, ""));
                                }
                                else
                                {
                                    return(await PostDeleteMinorGalleryFlowArticleAsync(delParam, result.Replace("true||", "")));
                                }
                            }
                            else if (result == "false||비밀번호 인증에 실패하였습니다. 다시 시도해주세요" ||
                                     result == "false|| 비밀번호가 맞지 않습니다. 다시 시도해주세요" ||
                                     result == "false||비밀번호가 잘못되었습니다. 다시 시도해주세요")
                            {
                                return(new DeleteResult(false, "비밀번호가 다릅니다."));
                            }
                            else
                            {
                                return(new DeleteResult(false, "알 수 없는 오류입니다."));
                            }
                        }
                    }
                }
        }