public async Task <Post> CreateNewThreadPreviewAsync(NewThread newThreadEntity) { if (!_webManager.IsAuthenticated) { throw new Exception("User must be authenticated before using this method."); } var result = new Result(); // We post to SA the same way we would for a normal reply, but instead of getting a redirect back to the // thread, we'll get redirected to back to the reply screen with the preview message on it. // From here we can parse that preview and return it to the user. var form = new MultipartFormDataContent { { new StringContent("postthread"), "action" }, { new StringContent(newThreadEntity.ForumId.ToString(CultureInfo.InvariantCulture)), "forumid" }, { new StringContent(newThreadEntity.FormKey), "formkey" }, { new StringContent(newThreadEntity.FormCookie), "form_cookie" }, { new StringContent(newThreadEntity.PostIcon.Id.ToString(CultureInfo.InvariantCulture)), "iconid" }, { new StringContent(HtmlHelpers.HtmlEncode(newThreadEntity.Subject)), "subject" }, { new StringContent(HtmlHelpers.HtmlEncode(newThreadEntity.Content)), "message" }, { new StringContent(newThreadEntity.ParseUrl.ToString()), "parseurl" }, { new StringContent("Submit Post"), "submit" }, { new StringContent("Preview Post"), "preview" } }; result = await _webManager.PostFormDataAsync(EndPoints.NewThreadBase, form); return(PostHandler.ParsePostPreview(_webManager.Parser.Parse(result.ResultHtml))); }
public async Task <Post> CreateNewThreadPreviewAsync(NewThread newThreadEntity, CancellationToken token = default) { if (newThreadEntity == null) { throw new ArgumentNullException(nameof(newThreadEntity)); } if (!this.webManager.IsAuthenticated) { throw new UserAuthenticationException(Awful.Core.Resources.ExceptionMessages.UserAuthenticationError); } // We post to SA the same way we would for a normal reply, but instead of getting a redirect back to the // thread, we'll get redirected to back to the reply screen with the preview message on it. // From here we can parse that preview and return it to the user. using var form = new MultipartFormDataContent { { new StringContent("postthread"), "action" }, { new StringContent(newThreadEntity.ForumId.ToString(CultureInfo.InvariantCulture)), "forumid" }, { new StringContent(newThreadEntity.FormKey), "formkey" }, { new StringContent(newThreadEntity.FormCookie), "form_cookie" }, { new StringContent(newThreadEntity.PostIcon.Id.ToString(CultureInfo.InvariantCulture)), "iconid" }, { new StringContent(HtmlHelpers.HtmlEncode(newThreadEntity.Subject)), "subject" }, { new StringContent(HtmlHelpers.HtmlEncode(newThreadEntity.Content)), "message" }, { new StringContent(newThreadEntity.ParseUrl.ToString()), "parseurl" }, { new StringContent("Submit Post"), "submit" }, { new StringContent("Preview Post"), "preview" }, }; var result = await this.webManager.PostFormDataAsync(EndPoints.NewThreadBase, form, token).ConfigureAwait(false); return(PostHandler.ParsePostPreview(await this.webManager.Parser.ParseDocumentAsync(result.ResultHtml, token).ConfigureAwait(false))); }