网站中部分代码:
protected void Page_Load(object sender, EventArgs e)
{
Stream stream = Request.InputStream;
byte[] buffer = new byte[Convert.ToInt32(stream.Length)];
if (buffer.Length > 0)
{
stream.Read(buffer, 0, buffer.Length);
string mac = lycommon.Serialization.GetObjectFromSerialization(buffer).ToString();
lycommon.Users userinfo = (lycommon.Users)lycommon.Serialization.GetObjectFromSerialization(buffer);
Dao.Users u = new Dao.Users();
int id = u.Set(userinfo);
userinfo.ID = id;
List<lycommon.SClass> _myclass = u.GetClass(userinfo);
object[] objresult = new object[] { userinfo, _myclass };
byte[] bresult = lycommon.Serialization.ToSerialization(objresult);
Response.BinaryWrite(bresult);
}
else
{
Response.Write("no data");
}
Response.End();
}
客户端部分代码:
string mac = "1C:65:9D:43:3C:09";
lycommon.Users userinfo = new lycommon.Users();
userinfo.Mac = mac;
byte[] bmac = lycommon.Serialization.ToSerialization(userinfo);
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://localhost/toclient/zy_user.aspx");
req.Proxy = null;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = bmac.Length;
System.IO.Stream netStream = req.GetRequestStream();
netStream.Write(bmac, 0, bmac.Length);
netStream.Close();
System.Net.HttpWebResponse rep = (System.Net.HttpWebResponse)req.GetResponse();
Stream getStream = rep.GetResponseStream();
MemoryStream ms = new MemoryStream();
byte[] bresult = new byte[1024];
int bytes;
while ((bytes = getStream.Read(bresult, 0, bresult.Length)) > 0)
{
ms.Write(bresult, 0, bytes);
}
bresult = ms.GetBuffer();
ms.Close();
object[] objresult = (object[])lycommon.Serialization.GetObjectFromSerialization(bresult);
lycommon.Users result = (lycommon.Users)objresult[0];
List<lycommon.SClass> _myclass = (List<lycommon.SClass>)objresult[1];
rep.Close();
foreach (lycommon.SClass sclass in _myclass)
{
}
发送与接收的都是序列化后的二进制数据