static void send(MainForm frm) { Uri URL = new Uri(Program.url + "/insert_bug.aspx"); ExtendedWebClient extendedWebClient = new ExtendedWebClient(); CredentialCache myCredCache = new CredentialCache(); myCredCache.Add(URL, "Basic", new NetworkCredential(Program.username, Program.password)); myCredCache.Add(URL, "NTLM", new NetworkCredential(Program.username, Program.password, Program.domain)); extendedWebClient.Credentials = myCredCache; System.IO.MemoryStream ms = new System.IO.MemoryStream(); frm.getBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); string base64 = System.Convert.ToBase64String(ms.ToArray()); ms.Close(); ms.Dispose(); try { // Anmelden per POST; anonymer Typ als Parameterobjekt WebRequest req = extendedWebClient.Post(URL, new { username = Program.username, password = Program.password, bugid = frm.textBoxBugId.Text, short_desc = frm.textBoxShortDescription.Text, projectid = Convert.ToString(Program.project_id), attachment_content_type = "image/jpg", attachment_filename = String.Format("screenshot_{0}.jpg", DateTime.Now.ToString("yyyyMMdd'_'HHmmss")), attachment = base64 }); WebResponse res = (WebResponse)req.GetResponse(); frm.BeginInvoke(new MainForm.ResponseDelegate(frm.handleResponse), res); } catch (Exception e2) { frm.BeginInvoke(new MainForm.ResponseDelegate(frm.handleResponse), e2); } }
public static void threadproc(object obj) { MainForm frm = (MainForm)obj; StringBuilder sb = new StringBuilder(); sb.Append("username="******"&password="******"&short_desc=" + HttpUtility.UrlEncode(frm.textBoxShortDescription.Text)); sb.Append("&projectid=" + Convert.ToString(Program.project_id)); if (frm.radioButtonUpdateExisting.Checked) { sb.Append("&bugid=" + frm.textBoxBugId.Text); } sb.Append("&attachment_content_type=image/jpg"); sb.AppendFormat("&attachment_filename=screenshot_{0}.jpg", DateTime.Now.ToString("yyyyMMdd'_'HHmmss")); //Ash <2010-08-03> //sb.Append("&attachment_desc=screenshot"); sb.Append("&attachment_desc=" + HttpUtility.UrlEncode(frm.textBoxShortDescription.Text)); //End Ash <2010-08-03> sb.Append("&attachment="); System.IO.MemoryStream ms = new System.IO.MemoryStream(); frm.getBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); string base64 = System.Convert.ToBase64String(ms.ToArray()); ms.Close(); ms.Dispose(); sb.Append(HttpUtility.UrlEncode(base64)); // System.Byte[] byte_array2 = System.Convert.FromBase64String(base64); byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString()); // send request to web server HttpWebResponse res = null; try { HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create(Program.url + "/insert_bug.aspx"); req.Credentials = CredentialCache.DefaultCredentials; req.PreAuthenticate = true; //req.Timeout = 200; // maybe? //req.KeepAlive = false; // maybe? req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = bytes.Length; System.IO.Stream request_stream = req.GetRequestStream(); request_stream.Write(bytes, 0, bytes.Length); request_stream.Close(); res = (HttpWebResponse)req.GetResponse(); frm.BeginInvoke(new MainForm.ResponseDelegate(frm.handleResponse), res); } catch (Exception e2) { frm.BeginInvoke(new MainForm.ResponseDelegate(frm.handleResponse), e2); } }