public static void myRequest() { //string url = setting.serverUrl; //string url = myfile.ReadFile(1); string url = Conf.getUrl(); string content = "NULL"; if (url.Equals("NULL") == true) { MessageBox.Show("请去设置页面设置服务器地址!!!"); } else { try { WebRequest webrequest = WebRequest.Create(url); WebResponse webresponse = webrequest.GetResponse(); webrequest.Timeout = 10000; Stream stream = webresponse.GetResponseStream(); StreamReader sr = new StreamReader(stream); content = sr.ReadToEnd().ToString(); webresponse.Close(); webrequest.Abort(); System.GC.Collect(); MessageBox.Show(content); } catch (UriFormatException e) { MessageBox.Show("您输入的地址不规范,请重新输入地址!"); } catch (System.Net.WebException e) { MessageBox.Show("您输入的地址不规范,请重新输入地址!"); } } }
public static string myRequest1() { //string url = setting.serverUrl; //string url = myfile.ReadFile(1); string result = null; string url = Conf.getUrl(); string content = "NULL"; if (url.Equals("NULL") == true) { //MessageBox.Show("请去设置页面设置服务器地址!!!"); string s = "请去设置页面设置服务器地址!!!"; return(s); } else { try { WebRequest webrequest = WebRequest.Create(url); WebResponse webresponse = webrequest.GetResponse(); webrequest.Timeout = 10000; Stream stream = webresponse.GetResponseStream(); StreamReader sr = new StreamReader(stream); content = sr.ReadToEnd().ToString().Trim(); webresponse.Close(); webrequest.Abort(); System.GC.Collect(); //MessageBox.Show(content); string path = Environment.CurrentDirectory.ToString(); string urlfilename = path + "url.txt"; string userfilename = path + "name.txt"; string passfilename = path + "password.txt"; // myfile.CreateFile(userfilename); result = content; return(result); MessageBox.Show(result); } catch (UriFormatException e) { //MessageBox.Show("您输入的地址不规范,请重新输入地址!"); return(result); } catch (System.Net.WebException e) { //MessageBox.Show("您输入的地址不规范,请重新输入地址!"); return(result); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (this.texturl.Text != null) { serverurl = this.texturl.Text.ToString(); Conf.setServerUrl(serverurl); Conf.getUrl(); connectServerl.myRequest(); } else { MessageBox.Show("请填写服务器地址!!"); } if (this.textcom.Text != null) { comNumber = this.textcom.Text.ToString(); Conf.setCOM(comNumber); } else { MessageBox.Show("请填写COM口号!"); } this.Close(); }