/// <summary> /// 发送文件名称 到服务器端 /// </summary> /// <param name="url">服务器路径</param> /// <param name="xml">参数的值</param> string contentBack; public void PostFileName(string url, string name,string registerNum) { string postData = name + "&" + registerNum; byte[] bytes = Encoding.UTF7.GetBytes(postData); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentLength = bytes.Length; request.ContentType = "application/x-www-form-urlencoded";
try { using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); requestStream.Close();
//响应请求 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF7); contentBack = reader.ReadLine(); //MessageBox.Show(contentBack, "服务器消息:"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } }
服务器端的接受://获得参数的值 Stream str = Request.InputStream; int strLen, strRead; strLen = System.Convert.ToInt32(str.Length); Byte[] strArr = new Byte[strLen]; strRead = str.Read(strArr, 0, strLen); char[] strChar = System.Text.Encoding.Default.GetChars(strArr); string s = new String(strChar);
if (s =="") { return; }
//切割参数 string[] strArray = s.Split(new char[]{'&'}); string imei =strArray[0]; string code =strArray[1];
转载于:https://www.cnblogs.com/hxycn/archive/2009/08/21/1551551.html