private void onLoginClicked() { string name = txtName.Text.Trim(); string pass = txtPass.Text.Trim(); if (name.Length == 0 || pass.Length == 0) { MessageBox.Show("用户名和密码不能为空!"); return; } //string url = "http://10.9.37.100:8099/agile/login?username="******"&password="******"http://10.9.37.21:8099/agile/login?username="******"&password="******"GET"; //req.TransferEncoding = "utf-8"; HttpWebResponse myResponse = null; try { myResponse = req.GetResponse() as HttpWebResponse; StreamReader sr = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string res = sr.ReadToEnd(); //MessageBox.Show("aaa:" + res); LoginReturn r = JsonConvert.DeserializeObject <LoginReturn>(res); if (r.status == 200) { //MessageBox.Show(r.msg); User.sName = name; User.sPass = pass; this.DialogResult = DialogResult.OK; this.Close(); } else { //MessageBox.Show(r.msg); MessageBox.Show(res); //MessageBox.Show(r.status.ToString()); } //return res; } catch (WebException ex) { MessageBox.Show(ex.Message); } catch (Exception ex2) { MessageBox.Show(ex2.Message); } }
public static void postData(string paramData) { Document curDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = curDoc.Database; Editor ed = curDoc.Editor; try { ed.WriteMessage(paramData); string responseContent = ""; //string postUrl = "http://10.9.37.100:8099/agile/save"; string postUrl = "http://10.9.37.21:8099/agile/save"; byte[] byteArray = Encoding.UTF8.GetBytes(paramData); //转化 HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); webReq.Method = "POST"; //webReq.TransferEncoding = "utf-8"; //webReq.SendChunked = true; webReq.Headers.Add("charset", "utf-8"); webReq.ContentType = "application/json"; webReq.ContentLength = byteArray.Length; using (Stream reqStream = webReq.GetRequestStream()) { reqStream.Write(byteArray, 0, byteArray.Length);//写入参数 //reqStream.Close(); } using (HttpWebResponse response = (HttpWebResponse)webReq.GetResponse()) { //在这里对接收到的页面内容进行处理 using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { responseContent = sr.ReadToEnd().ToString(); LoginReturn r = JsonConvert.DeserializeObject <LoginReturn>(responseContent); if (r.status == 200) { System.Diagnostics.Process.Start(r.msg); } else { MessageBox.Show(responseContent); } } } } catch (System.Exception ex) { MessageBox.Show("ex68:" + ex.Message); } }