C#POST数据问题
我在客户端(win7触屏)创建了一个winform,并内嵌了两个webbrowser对特定网址进行访问,我现在要实现访问统计功能,即当客户端没发生一次鼠标移动事件,客户端...
我在客户端(win7 触屏)创建了一个winform,并内嵌了两个webbrowser对特定网址进行访问,我现在要实现访问统计功能,即当客户端没发生一次鼠标移动事件,客户端就向服务器POST一次(并传输本身的MAC地址),请问怎么实现?说的详细些,给出代码,谢了
展开
1个回答
展开全部
在鼠标点击事件中调用服务器的接口,获取到本机mac地址,通过接口传递给服务器
CookieContainer cc = new CookieContainer();
string url = "服务器http接口";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
request.KeepAlive = true;
request.CookieContainer = cc;
string date = "MAC=xxxxxxx";
request.ContentLength = date.Length;
StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
writer.Write(date);
writer.Flush();
CookieContainer cc = new CookieContainer();
string url = "服务器http接口";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
request.KeepAlive = true;
request.CookieContainer = cc;
string date = "MAC=xxxxxxx";
request.ContentLength = date.Length;
StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
writer.Write(date);
writer.Flush();
追问
请问服务器端如何接收
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询