后台模拟一个http请求如何做? 比如想在一个button事件中,自己定义一个html字符串发出post或get的http请求,另一个页面request接收,就和html submit的一样,如何做?用httpwebrequest+httpwebresponse? 能给个例子吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HttpWebRequest通过post等提交到相关页面,获取执行的页面数据byte[] bdata = Encoding.Default.GetBytes(postData); System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(""); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = bdata.Length; Stream newStream = myRequest.GetRequestStream(); HttpWebRequest通过post等提交到相关页面,获取执行的页面数据private string HttpWebRequestLogin(string loginUrl, string postData, ref CookieContainer cookieContainer) { byte[] bdata = Encoding.Default.GetBytes(postData); System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrl); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; myRequest.Referer = loginUrl; myRequest.KeepAlive = true; myRequest.AllowAutoRedirect = true; if (cookieContainer == null) cookieContainer = new CookieContainer(); myRequest.CookieContainer = cookieContainer; myRequest.ContentLength = bdata.Length; Stream newStream = myRequest.GetRequestStream(); newStream.Write(l_data, 0, bdata.Length); newStream.Close(); HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("GB2312")); string content = reader.ReadToEnd(); return content; } 但是如何设置参数名了。比如人家提供的接口是request["name"]该如何办呢 .net中前台界面怎么调用后台的一个变量???? 在弹出一个无工具栏的全屏窗口后,怎样用JS再把工具栏加上 如何控制文件的下载权限? 如何才能将数据库中的编号字段完整输出 Image控件这么在.cs添加链接? 急!~制作报表的问题 asp.net 服务的头痛问题~~在线等~~谢谢大家 ASP.NET获取服务器信息命令集合 关于OBJECT哪位大虾知道,赶快进呀!帮小弟解决问题呀!:) 有没有ASP.NET对数据进行SSL加密的源码 动态网站里的一些通用内容怎么设置比较好? 利用ajax技术实现一个页面不刷新的,并且验证一个用户名是否被注册的过程.
byte[] bdata = Encoding.Default.GetBytes(postData);
System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = bdata.Length;
Stream newStream = myRequest.GetRequestStream();
private string HttpWebRequestLogin(string loginUrl, string postData, ref CookieContainer cookieContainer)
{
byte[] bdata = Encoding.Default.GetBytes(postData);
System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(loginUrl);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
myRequest.Referer = loginUrl;
myRequest.KeepAlive = true;
myRequest.AllowAutoRedirect = true;
if (cookieContainer == null)
cookieContainer = new CookieContainer();
myRequest.CookieContainer = cookieContainer;
myRequest.ContentLength = bdata.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(l_data, 0, bdata.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("GB2312"));
string content = reader.ReadToEnd();
return content;
}