/// <summary> /// Post a report to a website, without exception handling. /// </summary> /// <param name="link">Web URL to post report to</param> /// <param name="postData">Report text</param> public static void PostToLink(string link, string postData) { string filePath = Path.GetTempFileName() + @".html"; string javaScript = string.Format( @"<script type=""text/javascript""> function submitForm() {{ document.getElementById(""my_form"").submit(); }} window.onload = submitForm; </script> <form id=""my_form"" action=""{0}"" method=""post"" style=""visibility: hidden;""> <textarea name=""SkylineReport"">{1}</textarea> </form>", link, WebUtility.HtmlEncode(postData)); try { using (var saver = new FileSaver(filePath)) { using (var writer = new StreamWriter(saver.SafeName)) { writer.Write(javaScript); writer.Flush(); writer.Close(); } saver.Commit(); } } catch (Exception) { throw new IOException(Resources.WebHelpers_PostToLink_Failure_saving_temporary_post_data_to_disk_); } try { // CONSIDER: User could have a configuration that opens html documents // with a text editor. This would defeat the redirection and post. Process.Start(filePath); } catch (Exception) { throw new WebToolException(Resources.Could_not_open_web_Browser_to_show_link_, link); } DeleteTempHelper d = new DeleteTempHelper(filePath); Thread t = new Thread(d.DeletePath); t.Start(); }
/// <summary> /// Post a report to a website, without exception handling. /// </summary> /// <param name="link">Web URL to post report to</param> /// <param name="postData">Report text</param> public static void PostToLink(string link, string postData) { string filePath = Path.GetTempFileName() + ".html"; // Not L10N string javaScript = string.Format( @"<script type=""text/javascript""> function submitForm() {{ document.getElementById(""my_form"").submit(); }} window.onload = submitForm; </script> <form id=""my_form"" action=""{0}"" method=""post"" style=""visibility: hidden;""> <textarea name=""SkylineReport"">{1}</textarea> </form>", // Not L10N link, WebUtility.HtmlEncode(postData)); try { using (var saver = new FileSaver(filePath)) { using (var writer = new StreamWriter(saver.SafeName)) { writer.Write(javaScript); writer.Flush(); writer.Close(); } saver.Commit(); } } catch (Exception) { throw new IOException(Resources.WebHelpers_PostToLink_Failure_saving_temporary_post_data_to_disk_); } try { // CONSIDER: User could have a configuration that opens html documents // with a text editor. This would defeat the redirection and post. Process.Start(filePath); } catch(Exception) { throw new WebToolException(Resources.Could_not_open_web_Browser_to_show_link_, link); } DeleteTempHelper d = new DeleteTempHelper(filePath); Thread t = new Thread(d.DeletePath); t.Start(); }