public static Remoting Instance(string key, out string error) { Remoting remoting = null; error = "认证失败"; try { var client = new WebClient(); var args = new System.Collections.Specialized.NameValueCollection(); args.Add("key", key); //var buffer = client.DownloadData(App.Default.ServiceURI); var buffer = client.UploadValues(App.Default.ServiceURI + "/login.aspx", "POST", args); var response = Encoding.UTF8.GetString(buffer); var result = JsonConvert.DeserializeObject <JsonResponse>(response); error = result.Error; if (string.IsNullOrEmpty(result.Error)) { error = ""; client.Headers.Add("Cookie", client.ResponseHeaders["Set-Cookie"]); remoting = new Remoting() { Web = client }; } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(remoting); }
private void ButtonStart_Click(object sender, EventArgs e) { //var main = new Main(); //main.Show(); Cursor = Cursors.WaitCursor; this.Enabled = false; var message = ""; var remoting = Remoting.Instance("key", out message); Cursor = Cursors.Default; if (remoting == null) { MessageBox.Show(message, "错误"); } else { Main.RemotingInstance = remoting; DialogResult = System.Windows.Forms.DialogResult.OK; } this.Cursor = Cursors.Default; this.Enabled = true; }