frmMain.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Text.RegularExpressions;
  11. using System.Collections.Specialized;
  12. using System.Net;
  13. using System.IO;
  14. namespace CustomRequest {
  15. public partial class frmMain : Form {
  16. public frmMain() {
  17. InitializeComponent();
  18. }
  19. private DataGridViewRow rowHost;
  20. private DataGridViewRow rowPath;
  21. private DataGridViewRow rowHTTP;
  22. private Regex regUrl = new Regex("^((?<protocol>https?)\\:\\/\\/)?(?<host>[a-zA-Z0-9\\.\\-_]+)(?<path>\\/.*?)?(?<query>\\?.*?)?$", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
  23. private void frmMain_Load(object sender, EventArgs e) {
  24. this.New();
  25. string[] arguments = Environment.GetCommandLineArgs();
  26. if(arguments.Length>1) {
  27. if (this.LoadFile(arguments[1]))
  28. this.Run();
  29. }
  30. }
  31. public void New() {
  32. initRequestheaderView();
  33. this.txtResponse.Text = "";
  34. this.txtResponseCode.Text = "";
  35. this.txtUrl.Text = "";
  36. this.dgvCookies.Rows.Clear();
  37. this.dgvGET.Rows.Clear();
  38. this.dgvPOST.Rows.Clear();
  39. }
  40. protected void initRequestheaderView() {
  41. this.rowHost = new DataGridViewRow();
  42. this.rowPath = new DataGridViewRow();
  43. this.rowHTTP = new DataGridViewRow();
  44. DataGridViewRow rowMethod = new DataGridViewRow();
  45. rowMethod.Cells.AddRange(new DataGridViewCell[] {
  46. new DataGridViewTextBoxCell() { Value = "Method" },
  47. new DataGridViewCheckBoxCell() { Value = true },
  48. //new DataGridViewTextBoxCell() { Value = "GET" }
  49. new DataGridViewComboBoxCell() { Value = "GET" }
  50. });
  51. ((DataGridViewComboBoxCell)rowMethod.Cells[2]).Items.AddRange("GET", "POST", "PATCH", "PUT", "CONNECT", "HEAD", "DELETE", "TRACE");
  52. rowPath.Cells.AddRange(new DataGridViewCell[] {
  53. new DataGridViewTextBoxCell() { Value = "Path" },
  54. new DataGridViewCheckBoxCell() { Value = true },
  55. new DataGridViewTextBoxCell() { Value = "" }
  56. });
  57. rowHTTP.Cells.AddRange(new DataGridViewCell[] {
  58. new DataGridViewTextBoxCell() { Value = "HTTP Version" },
  59. new DataGridViewCheckBoxCell() { Value = true },
  60. new DataGridViewComboBoxCell() { Value = "HTTP/1.1" }
  61. });
  62. ((DataGridViewComboBoxCell)rowHTTP.Cells[2]).Items.AddRange("HTTP/1.0", "HTTP/1.1");
  63. rowHost.Cells.AddRange(new DataGridViewCell[] {
  64. new DataGridViewTextBoxCell() { Value = "host" },
  65. new DataGridViewCheckBoxCell() { Value = true },
  66. new DataGridViewTextBoxCell() { Value = "" }
  67. });
  68. DataGridViewRow rowConnection = new DataGridViewRow();
  69. rowConnection.Cells.AddRange(new DataGridViewCell[] {
  70. new DataGridViewTextBoxCell() { Value = "Connection" },
  71. new DataGridViewCheckBoxCell() { Value = true },
  72. new DataGridViewComboBoxCell() { Value = "Close" }
  73. });
  74. ((DataGridViewComboBoxCell)rowConnection.Cells[2]).Items.AddRange("Close", "keep-alive");
  75. DataGridViewRow rowContentType = new DataGridViewRow();
  76. rowContentType.Cells.AddRange(new DataGridViewCell[] {
  77. new DataGridViewTextBoxCell() { Value = "Content-Type" },
  78. new DataGridViewCheckBoxCell() { Value = false },
  79. new DataGridViewTextBoxCell() { Value = "application/x-www-form-urlencoded" }
  80. });
  81. DataGridViewRow rowContentLength = new DataGridViewRow();
  82. rowContentLength.Cells.AddRange(new DataGridViewCell[] {
  83. new DataGridViewTextBoxCell() { Value = "Content-Length" },
  84. new DataGridViewCheckBoxCell() { Value = false },
  85. new DataGridViewTextBoxCell() { Value = "auto" }
  86. });
  87. DataGridViewRow rowPragma = new DataGridViewRow();
  88. rowPragma.Cells.AddRange(new DataGridViewCell[] {
  89. new DataGridViewTextBoxCell() { Value = "pragma" },
  90. new DataGridViewCheckBoxCell() { Value = true },
  91. new DataGridViewTextBoxCell() { Value = "no-cache" }
  92. });
  93. DataGridViewRow rowCacheControl = new DataGridViewRow();
  94. rowCacheControl.Cells.AddRange(new DataGridViewCell[] {
  95. new DataGridViewTextBoxCell() { Value = "cache-control" },
  96. new DataGridViewCheckBoxCell() { Value = true },
  97. new DataGridViewTextBoxCell() { Value = "no-cache" }
  98. });
  99. DataGridViewRow rowUpgradeInsecureRequests = new DataGridViewRow();
  100. rowUpgradeInsecureRequests.Cells.AddRange(new DataGridViewCell[] {
  101. new DataGridViewTextBoxCell() { Value = "Upgrade-Insecure-Requests" },
  102. new DataGridViewCheckBoxCell() { Value = true },
  103. new DataGridViewTextBoxCell() { Value = "1" }
  104. });
  105. DataGridViewRow rowUserAgent = new DataGridViewRow();
  106. rowUserAgent.Cells.AddRange(new DataGridViewCell[] {
  107. new DataGridViewTextBoxCell() { Value = "User-Agent" },
  108. new DataGridViewCheckBoxCell() { Value = true },
  109. new DataGridViewTextBoxCell() { Value = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.158 Safari/537.36 Vivaldi/2.5.1525.43" }
  110. });
  111. DataGridViewRow rowDNT = new DataGridViewRow();
  112. rowDNT.Cells.AddRange(new DataGridViewCell[] {
  113. new DataGridViewTextBoxCell() { Value = "DNT" },
  114. new DataGridViewCheckBoxCell() { Value = true },
  115. new DataGridViewTextBoxCell() { Value = "1" }
  116. });
  117. rowDNT.Cells[0].ToolTipText = "Do not Track";
  118. DataGridViewRow rowAccept = new DataGridViewRow();
  119. rowAccept.Cells.AddRange(new DataGridViewCell[] {
  120. new DataGridViewTextBoxCell() { Value = "Accept" },
  121. new DataGridViewCheckBoxCell() { Value = true },
  122. new DataGridViewTextBoxCell() { Value = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" }
  123. });
  124. DataGridViewRow rowReferer = new DataGridViewRow();
  125. rowReferer.Cells.AddRange(new DataGridViewCell[] {
  126. new DataGridViewTextBoxCell() { Value = "referer" },
  127. new DataGridViewCheckBoxCell() { Value = false },
  128. new DataGridViewTextBoxCell() { Value = "https://www.google.com/" }
  129. });
  130. DataGridViewRow rowAcceptEncoding = new DataGridViewRow();
  131. rowAcceptEncoding.Cells.AddRange(new DataGridViewCell[] {
  132. new DataGridViewTextBoxCell() { Value = "Accept-Encoding" },
  133. new DataGridViewCheckBoxCell() { Value = true },
  134. new DataGridViewTextBoxCell() { Value = "gzip, deflate" }
  135. });
  136. DataGridViewRow rowAcceptLanguage = new DataGridViewRow();
  137. rowAcceptLanguage.Cells.AddRange(new DataGridViewCell[] {
  138. new DataGridViewTextBoxCell() { Value = "Accept-Language" },
  139. new DataGridViewCheckBoxCell() { Value = true },
  140. new DataGridViewTextBoxCell() { Value = "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7" }
  141. });
  142. dgvRequest.Rows.Clear();
  143. dgvRequest.Rows.AddRange(new DataGridViewRow[] {
  144. rowMethod,
  145. rowPath,
  146. rowHTTP,
  147. rowHost,
  148. rowConnection,
  149. rowPragma,
  150. rowUpgradeInsecureRequests,
  151. rowUserAgent,
  152. rowDNT,
  153. rowAccept,
  154. rowReferer,
  155. rowAcceptEncoding,
  156. rowAcceptLanguage
  157. });
  158. }
  159. private void txtUrl_TextChanged(object sender, EventArgs e) {
  160. if(string.IsNullOrEmpty(txtUrl.Text)) {
  161. rowHost.Cells[2].Value = "";
  162. rowPath.Cells[2].Value = "";
  163. } else {
  164. Match m = regUrl.Match(this.txtUrl.Text);
  165. if (m.Groups["host"].Success)
  166. rowHost.Cells[2].Value = m.Groups["host"].Value;
  167. if (m.Groups["path"].Success)
  168. rowPath.Cells[2].Value = m.Groups["path"].Value;
  169. }
  170. }
  171. private void cmdSend_Click(object sender, EventArgs e) {
  172. this.Run();
  173. }
  174. protected void Run() {
  175. string dt = DateTime.Now.Year.ToString() + "_" + (DateTime.Now.Month < 10 ? "0" : "") + DateTime.Now.Month + "_" + (DateTime.Now.Day < 10 ? "0" : "") + DateTime.Now.Day + "_" + (DateTime.Now.Hour < 10 ? "0" : "") + DateTime.Now.Hour + "_" + (DateTime.Now.Minute < 10 ? "0" : "") + DateTime.Now.Minute;
  176. string index = "";
  177. if (!System.IO.Directory.Exists("log/"))
  178. System.IO.Directory.CreateDirectory("log/");
  179. for(int i=1;i<10;i++) {
  180. if (!System.IO.File.Exists("log / request_" + dt + index + ".log"))
  181. break;
  182. else
  183. index = "_" + i;
  184. }
  185. System.IO.StreamWriter sw = new StreamWriter("log/request_"+dt+index+".log");
  186. tslState.Text = "Check Header";
  187. tslProgress.Maximum = 100;
  188. tslProgress.Value = 0;
  189. tslState.Visible = true;
  190. tslError.Visible = false;
  191. tslProgress.Visible = true;
  192. bool bValidHeader = CheckHeader();
  193. tslProgress.Value = 5;
  194. tslState.Text = "Generate Header";
  195. NameValueCollection header = GenerateHeader();
  196. tslProgress.Value = 10;
  197. tslProgress.Visible = false;
  198. string cookieStr = "";
  199. sw.WriteLine("Basis Info\r\n----------------------------------------------------------");
  200. string[] urlParts = txtUrl.Text.Split('?');
  201. string url = urlParts[0];
  202. string query = "";
  203. foreach(DataGridViewRow row in this.dgvGET.Rows) {
  204. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  205. if (!string.IsNullOrEmpty((string)row.Cells[2].Value))
  206. query += (query.Length == 0 ? "?" : "&") + WebUtility.UrlEncode(row.Cells[0].Value.ToString()) + "=" + WebUtility.UrlEncode(row.Cells[2].Value.ToString());
  207. }
  208. }
  209. sw.WriteLine("Send query: " + query);
  210. System.Diagnostics.Debug.WriteLine("Send Query: " + query);
  211. foreach (DataGridViewRow row in this.dgvCookies.Rows) {
  212. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  213. if (!string.IsNullOrEmpty((string)row.Cells[2].Value))
  214. cookieStr += (cookieStr.Length == 0 ? "" : "; ") + row.Cells[0].Value.ToString() + "=" + row.Cells[2].Value.ToString();
  215. }
  216. }
  217. sw.WriteLine("Send cookie: " + cookieStr);
  218. System.Diagnostics.Debug.WriteLine("Send Cookie: " + cookieStr);
  219. tslProgress.Value = 15;
  220. tslState.Text = "Generate Content";
  221. string post = "";
  222. foreach (DataGridViewRow row in this.dgvPOST.Rows) {
  223. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  224. if (!string.IsNullOrEmpty((string)row.Cells[2].Value))
  225. post += (post.Length == 0 ? "" : "&") + WebUtility.UrlEncode(row.Cells[0].Value.ToString()) + "=" + WebUtility.UrlEncode(row.Cells[2].Value.ToString());
  226. }
  227. }
  228. sw.WriteLine("Send post: " + post);
  229. System.Diagnostics.Debug.WriteLine("Send Post: " + post);
  230. string callUrl = (url.Contains("://")?"":"http://") + url + (url.IndexOf("/",9)==-1?"/":"") + query;
  231. sw.WriteLine("URL: " + callUrl);
  232. sw.WriteLine("");
  233. System.Diagnostics.Debug.WriteLine(callUrl);
  234. HttpWebRequest request = WebRequest.CreateHttp(callUrl);
  235. request.Method = this.GetHeaderField("Method").ToUpper();
  236. request.AllowAutoRedirect = false;
  237. System.Diagnostics.Debug.WriteLine(request.Method + " " + callUrl.Substring(callUrl.IndexOf("/", 9)) + " HTTP/" + request.ProtocolVersion.Major.ToString() + "." + request.ProtocolVersion.Minor.ToString());
  238. sw.WriteLine("");
  239. sw.WriteLine("");
  240. sw.WriteLine("Request\r\n----------------------------------------------------------");
  241. sw.WriteLine(request.Method + " " + callUrl.Substring(callUrl.IndexOf("/", 9)) + " HTTP/" + request.ProtocolVersion.Major.ToString() + "." + request.ProtocolVersion.Minor.ToString());
  242. if (HasHeaderField("Host")) {
  243. request.Host = GetHeaderField("Host");
  244. }
  245. if (HasHeaderField("User-Agent")) {
  246. request.UserAgent = GetHeaderField("User-Agent");
  247. }
  248. if (HasHeaderField("Accept")) {
  249. request.Accept = GetHeaderField("Accept");
  250. }
  251. if (HasHeaderField("Content-Type")) {
  252. request.ContentType = GetHeaderField("Content-Type");
  253. }
  254. request.CookieContainer = new CookieContainer();
  255. foreach (DataGridViewRow row in this.dgvCookies.Rows) {
  256. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  257. if (!string.IsNullOrEmpty((string)row.Cells[2].Value) && !string.IsNullOrEmpty((string)row.Cells[0].Value))
  258. request.CookieContainer.Add(new Uri(txtUrl.Text), new Cookie((string)row.Cells[0].Value, (string)row.Cells[2].Value));
  259. }
  260. }
  261. //request.Headers.Add(header);
  262. foreach (string k in header.AllKeys) {
  263. try {
  264. request.Headers[k] = header[k];
  265. } catch(Exception ex) {
  266. System.Diagnostics.Debug.WriteLine("Failed to add Header: '" + k + "' = '" + header[k] + "'");
  267. }
  268. }
  269. if (request.Method=="POST") {
  270. string xlen = GetHeaderField("Content-Length").Trim().ToLower();
  271. if (!HasHeaderField("Content-Type") && !HasHeaderField("Content-Length")) {
  272. if(MessageBox.Show("Es wurde kein Content-Type und keine Content-Length gesetzt\r\nSollen die Felder automatisch befüllt werden?","POST Request", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
  273. request.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  274. xlen = "auto";
  275. }
  276. } else if(!HasHeaderField("Content-Type")) {
  277. if (MessageBox.Show("Es wurde kein Content-Type gesetzt\r\nSoll das Feld automatisch befüllt werden?", "POST Request", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
  278. request.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  279. }
  280. } else if (!HasHeaderField("Content-Length")) {
  281. if (MessageBox.Show("Es wurde keine Content-Length gesetzt\r\nSoll das Feld automatisch befüllt werden?", "POST Request", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
  282. xlen = "auto";
  283. }
  284. }
  285. string ct = header["Content-Type"];
  286. Encoding enc = System.Text.Encoding.ASCII;
  287. /*if (!String.IsNullOrEmpty(ct)) {
  288. ct = ct.ToLower();
  289. if (ct.Contains("utf8") || ct.Contains("utf-8")) {
  290. enc = Encoding.UTF8;
  291. } else if (ct.Contains("unicode") || ct.Contains("utf16") || ct.Contains("utf-8")) {
  292. enc = Encoding.Unicode;
  293. } else if (ct.Contains("utf32") || ct.Contains("utf-32")) {
  294. enc = Encoding.UTF32;
  295. }
  296. }*/
  297. byte[] content = enc.GetBytes(post);
  298. if (xlen == "auto")
  299. request.ContentLength = content.Length;
  300. else {
  301. long val = 0;
  302. if(long.TryParse(xlen, out val)) {
  303. request.ContentLength = val;
  304. } else {
  305. request.ContentLength = content.Length;
  306. }
  307. }
  308. Stream dataStream = request.GetRequestStream();
  309. dataStream.Write(content, 0, content.Length);
  310. dataStream.Close();
  311. sw.WriteLine("");
  312. sw.WriteLine(post);
  313. }
  314. foreach (string hKey in request.Headers.AllKeys) {
  315. sw.WriteLine(hKey + ": " + request.Headers[hKey]);
  316. System.Diagnostics.Debug.WriteLine(hKey + ": " + request.Headers[hKey]);
  317. }
  318. tslProgress.Value = 20;
  319. tslState.Text = "Sending...";
  320. sw.WriteLine("");
  321. sw.WriteLine("");
  322. sw.WriteLine("Response\r\n----------------------------------------------------------");
  323. WebResponse response = request.GetResponse();
  324. tslState.Text = "Get response";
  325. string resHeader = "";
  326. tslProgress.Value = 70;
  327. foreach (string k in response.Headers.AllKeys) {
  328. resHeader += k + ": " + response.Headers[k] + "\r\n";
  329. }
  330. sw.WriteLine(resHeader);
  331. this.txtResponse.Text = resHeader;
  332. tslProgress.Value = 75;
  333. Stream data = response.GetResponseStream();
  334. StreamReader tr = new StreamReader(data);
  335. string raw = tr.ReadToEnd();
  336. this.txtResponseCode.Text = raw;
  337. if(raw.Trim().Contains("<") && raw.Contains("<head") && raw.Contains("<html")) {
  338. string browserContent = raw;
  339. browserContent = Regex.Replace(browserContent, @"<script[^>]*>[\s\S]*?</script>", "", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  340. browserContent = Regex.Replace(browserContent, "(\\<script[^>]\\>)", "", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
  341. this.webBrowser1.DocumentText = browserContent;
  342. this.txtResponseCode.Text = browserContent;
  343. sw.WriteLine("");
  344. sw.WriteLine("");
  345. sw.WriteLine("Content\r\n----------------------------------------------------------");
  346. sw.WriteLine(raw);
  347. }
  348. sw.Close();
  349. }
  350. private bool CheckHeader() {
  351. bool res = true;
  352. string[] required = new string[] { "Path", "Method", "Host", "HTTP Version", "Connection" };
  353. foreach (string h in required) {
  354. if(!this.HasHeaderField(h)) {
  355. tslError.Text = "Header '" + h + "' required";
  356. return false;
  357. }
  358. }
  359. return false;
  360. }
  361. private bool HasHeaderField(string fieldName) {
  362. foreach (DataGridViewRow row in this.dgvRequest.Rows) {
  363. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  364. if (((string)row.Cells[0].Value).ToLower().Trim() == fieldName.ToLower().Trim())
  365. if (!string.IsNullOrEmpty((string)row.Cells[2].Value))
  366. return true;
  367. }
  368. }
  369. return false;
  370. }
  371. private string GetHeaderField(string fieldName) {
  372. foreach (DataGridViewRow row in this.dgvRequest.Rows) {
  373. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  374. if (((string)row.Cells[0].Value).ToLower().Trim() == fieldName.ToLower().Trim())
  375. if (!string.IsNullOrEmpty((string)row.Cells[2].Value))
  376. return (string)row.Cells[2].Value;
  377. }
  378. }
  379. return "";
  380. }
  381. private NameValueCollection GenerateHeader() {
  382. string query_string = "";
  383. NameValueCollection res = new NameValueCollection();
  384. foreach (DataGridViewRow row in this.dgvRequest.Rows) {
  385. if (row.Cells[1].Value != null && (bool)row.Cells[1].Value == true) {
  386. if (row.Cells[0].Value != null && !String.IsNullOrEmpty(row.Cells[2].Value.ToString()) && row.Cells[2].Value != null) {
  387. string var = row.Cells[0].Value.ToString().Trim();
  388. if(var!="Method" && var!="Path" && var!= "HTTP Version") {
  389. res[var] = row.Cells[2].Value.ToString();
  390. }
  391. }
  392. }
  393. }
  394. return res;
  395. }
  396. private void öffnenToolStripMenuItem_Click(object sender, EventArgs e) {
  397. openFileDialog1.Filter = "Request Dateien (*.req)|*.req|Alle Dateien|*.*";
  398. openFileDialog1.Title = "Öffnen";
  399. if(openFileDialog1.ShowDialog() == DialogResult.OK) {
  400. LoadFile(openFileDialog1.FileName);
  401. }
  402. }
  403. private string loadedFile = "";
  404. protected bool LoadFile(string file) {
  405. if (!System.IO.File.Exists(file))
  406. return false;
  407. this.loadedFile = file;
  408. SaveData s = System.Fire.Serialize.Serializer.DeserializeObject<SaveData>(file, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
  409. if(s==null) {
  410. return false;
  411. }
  412. this.New();
  413. this.txtUrl.Text = s.url;
  414. foreach (SaveData_Row r in s.headers) {
  415. DataGridViewRow row = new DataGridViewRow();
  416. row.Cells.AddRange(new DataGridViewCell[] {
  417. new DataGridViewTextBoxCell() { Value = r.variable},
  418. new DataGridViewCheckBoxCell() {Value = r.active},
  419. new DataGridViewTextBoxCell() { Value = r.value}
  420. });
  421. dgvRequest.Rows.Add(row);
  422. }
  423. foreach (SaveData_Row r in s.get) {
  424. DataGridViewRow row = new DataGridViewRow();
  425. row.Cells.AddRange(new DataGridViewCell[] {
  426. new DataGridViewTextBoxCell() { Value = r.variable},
  427. new DataGridViewCheckBoxCell() {Value = r.active},
  428. new DataGridViewTextBoxCell() { Value = r.value}
  429. });
  430. dgvGET.Rows.Add(row);
  431. }
  432. foreach (SaveData_Row r in s.post) {
  433. DataGridViewRow row = new DataGridViewRow();
  434. row.Cells.AddRange(new DataGridViewCell[] {
  435. new DataGridViewTextBoxCell() { Value = r.variable},
  436. new DataGridViewCheckBoxCell() {Value = r.active},
  437. new DataGridViewTextBoxCell() { Value = r.value}
  438. });
  439. dgvPOST.Rows.Add(row);
  440. }
  441. foreach (SaveData_Row r in s.cookies) {
  442. DataGridViewRow row = new DataGridViewRow();
  443. row.Cells.AddRange(new DataGridViewCell[] {
  444. new DataGridViewTextBoxCell() { Value = r.variable},
  445. new DataGridViewCheckBoxCell() {Value = r.active},
  446. new DataGridViewTextBoxCell() { Value = r.value}
  447. });
  448. dgvCookies.Rows.Add(row);
  449. }
  450. return true;
  451. }
  452. protected bool Save() {
  453. if(string.IsNullOrEmpty(this.loadedFile)) {
  454. return SaveAs();
  455. }
  456. return Save(this.loadedFile);
  457. }
  458. protected bool Save(string file) {
  459. this.loadedFile = file;
  460. SaveData s = new SaveData();
  461. s.url = txtUrl.Text;
  462. s.headers = new List<SaveData_Row>();
  463. foreach (DataGridViewRow row in this.dgvRequest.Rows) {
  464. if (row.Cells[0].Value != null) {
  465. s.headers.Add(new SaveData_Row() {
  466. variable = (string)row.Cells[0].Value,
  467. active = (row.Cells[1].Value == null ? false : (bool)row.Cells[1].Value == true),
  468. value = (row.Cells[0].Value==null?"":(string)row.Cells[2].Value)
  469. });
  470. }
  471. }
  472. s.get = new List<SaveData_Row>();
  473. foreach(DataGridViewRow row in this.dgvGET.Rows) {
  474. if (row.Cells[0].Value != null) {
  475. s.headers.Add(new SaveData_Row() {
  476. variable = (string)row.Cells[0].Value,
  477. active = (row.Cells[1].Value==null?false:(bool)row.Cells[1].Value == true),
  478. value = (row.Cells[0].Value == null ? "" : (string)row.Cells[2].Value)
  479. });
  480. }
  481. }
  482. s.post = new List<SaveData_Row>();
  483. foreach (DataGridViewRow row in this.dgvPOST.Rows) {
  484. if (row.Cells[0].Value != null) {
  485. s.headers.Add(new SaveData_Row() {
  486. variable = (string)row.Cells[0].Value,
  487. active = (row.Cells[1].Value == null ? false : (bool)row.Cells[1].Value == true),
  488. value = (row.Cells[0].Value == null ? "" : (string)row.Cells[2].Value)
  489. });
  490. }
  491. }
  492. s.cookies = new List<SaveData_Row>();
  493. foreach (DataGridViewRow row in this.dgvCookies.Rows) {
  494. if (row.Cells[0].Value != null) {
  495. s.headers.Add(new SaveData_Row() {
  496. variable = (string)row.Cells[0].Value,
  497. active = (row.Cells[1].Value == null ? false : (bool)row.Cells[1].Value == true),
  498. value = (row.Cells[0].Value == null ? "" : (string)row.Cells[2].Value)
  499. });
  500. }
  501. }
  502. System.Fire.Serialize.Serializer.SerializeObject(file, s, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
  503. return true;
  504. }
  505. protected bool SaveAs() {
  506. saveFileDialog1.Filter = "Request Dateien (*.req)|*.req|Alle Dateien|*.*"; ;
  507. saveFileDialog1.Title = "Speichern unter";
  508. if(saveFileDialog1.ShowDialog()== DialogResult.OK) {
  509. return this.Save(saveFileDialog1.FileName);
  510. }
  511. return false;
  512. }
  513. private void speichernToolStripMenuItem_Click(object sender, EventArgs e) {
  514. this.Save();
  515. }
  516. private void speichernUnterToolStripMenuItem_Click(object sender, EventArgs e) {
  517. this.SaveAs();
  518. }
  519. }
  520. }