c#的post问题
我现在需要将账号密码post到一个网站并接受返回的内容,post的内容保存在一个string里,请问如何写request和response。(webclient类你用过没...
我现在需要将账号密码post到一个网站并接受返回的内容,post的内容保存在一个string里,请问如何写request和response。(webclient类你用过没?那个可以直接post但我不太会用,帮我实现想要的就可以,谢谢)
展开
展开全部
在鼠标点击事件中调用服务器的接口,获取到本机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();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询