protected virtual async Task <string> RequestPostAsync(int pageNumber) { var requestRegistration = new CancellationTokenRegistration(); try { string url = "https://www.tumblr.com/search/" + Blog.Name + "/post_page/" + pageNumber; string referer = @"https://www.tumblr.com/search/" + Blog.Name; var headers = new Dictionary <string, string> { { "X-tumblr-form-key", tumblrKey }, { "DNT", "1" } }; HttpWebRequest request = WebRequestFactory.CreatePostXhrReqeust(url, referer, headers); CookieService.GetUriCookie(request.CookieContainer, new Uri("https://www.tumblr.com/")); //Example request body, searching for cars: //q=cars&sort=top&post_view=masonry&blogs_before=8&num_blogs_shown=8&num_posts_shown=20&before=24&blog_page=2&safe_mode=true&post_page=2&filter_nsfw=true&filter_post_type=&next_ad_offset=0&ad_placement_id=0&more_posts=true string requestBody = "q=" + Blog.Name + "&sort=top&post_view=masonry&num_posts_shown=" + ((pageNumber - 1) * Blog.PageSize) + "&before=" + ((pageNumber - 1) * Blog.PageSize) + "&safe_mode=false&post_page=" + pageNumber + "&filter_nsfw=false&filter_post_type=&next_ad_offset=0&ad_placement_id=0&more_posts=true"; await WebRequestFactory.PerformPostXHRReqeustAsync(request, requestBody); requestRegistration = Ct.Register(() => request.Abort()); return(await WebRequestFactory.ReadReqestToEndAsync(request)); } finally { requestRegistration.Dispose(); } }
protected async Task <string> RequestApiDataAsync(string url, string bearerToken, Dictionary <string, string> headers = null, IEnumerable <string> cookieHosts = null) { var requestRegistration = new CancellationTokenRegistration(); try { HttpWebRequest request = WebRequestFactory.CreateGetReqeust(url, string.Empty, headers); cookieHosts = cookieHosts ?? new List <string>(); foreach (string cookieHost in cookieHosts) { CookieService.GetUriCookie(request.CookieContainer, new Uri(cookieHost)); } request.PreAuthenticate = true; request.Headers.Add("Authorization", "Bearer " + bearerToken); request.Accept = "application/json"; requestRegistration = Ct.Register(() => request.Abort()); return(await WebRequestFactory.ReadReqestToEndAsync(request)); } finally { requestRegistration.Dispose(); } }
protected async Task <string> RequestDataAsync(string url, Dictionary <string, string> headers = null, IEnumerable <string> cookieHosts = null) { var requestRegistration = new CancellationTokenRegistration(); try { HttpWebRequest request = WebRequestFactory.CreateGetReqeust(url, string.Empty, headers); cookieHosts = cookieHosts ?? new List <string>(); foreach (string cookieHost in cookieHosts) { CookieService.GetUriCookie(request.CookieContainer, new Uri(cookieHost)); } requestRegistration = Ct.Register(() => request.Abort()); return(await WebRequestFactory.ReadReqestToEndAsync(request)); } finally { requestRegistration.Dispose(); } }
protected virtual async Task <string> RequestDataAsync(string limit, string offset) { var requestRegistration = new CancellationTokenRegistration(); try { string url = @"https://www.tumblr.com/svc/indash_blog?tumblelog_name_or_id=" + Blog.Name + @"&post_id=&limit=" + limit + "&offset=" + offset + "&should_bypass_safemode=true"; string referer = @"https://www.tumblr.com/dashboard/blog/" + Blog.Name; var headers = new Dictionary <string, string> { { "X-tumblr-form-key", tumblrKey } }; HttpWebRequest request = WebRequestFactory.CreateGetXhrReqeust(url, referer, headers); CookieService.GetUriCookie(request.CookieContainer, new Uri("https://www.tumblr.com/")); CookieService.GetUriCookie(request.CookieContainer, new Uri("https://" + Blog.Name.Replace("+", "-") + ".tumblr.com")); requestRegistration = Ct.Register(() => request.Abort()); return(await WebRequestFactory.ReadReqestToEndAsync(request)); } finally { requestRegistration.Dispose(); } }