Asp.net的post提交方式
在网上找了半天Asp.Net的Post提交方式,,代码都一样.stringurl="网址";HttpWebRequestreq=(HttpWebRequest)WebRe...
在网上找了半天Asp.Net的Post提交方式,,代码都一样.
string url = "网址";
HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);
string s = "要提交的数据";
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(LoginInfo);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr =sr.ReadToEnd();
Response.Write(line);
sr.Close();
res.Close();
..
LoginInfo跟line是什么意思啊..不懂.放在代码里报错,当前上下文中不存在..
求解...! 展开
string url = "网址";
HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);
string s = "要提交的数据";
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(LoginInfo);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr =sr.ReadToEnd();
Response.Write(line);
sr.Close();
res.Close();
..
LoginInfo跟line是什么意思啊..不懂.放在代码里报错,当前上下文中不存在..
求解...! 展开
2个回答
展开全部
//建立WebRequest对象,url目标地址
HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);
//这里的s 是啥个东西??搞不懂
string s = "要提交的数据";
//将LoginInfo转换为byte[]格式,这里的LoginInfo应该是你要传输的数据
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(LoginInfo);
//设置请求为POST方式,
req.Method = "POST";
//设置请求类型
req.ContentType = "application/x-www-form-urlencoded";
//请求发送的数据长度, 这里就很清楚了,请求数据是从LoginInfo转换来的
//前面的代码byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(LoginInfo);
req.ContentLength = requestBytes.Length;
//建立请求的输入流
Stream requestStream = req.GetRequestStream();
//从requestBytes中读取数据到输入流中
requestStream.Write(requestBytes, 0, requestBytes.Length);
//关闭输入流
requestStream.Close();
//获取响应对象
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//获取服务器返回流
StreamReader sr = new StreamReader(res.GetResponseStream(),System.Text.Encoding.Default);
//读取返回流数据,并赋值给backstr
string backstr =sr.ReadToEnd();
//页面输出line???? 应该是backstr 吧
Response.Write(line);
//关闭* 2, 不解释了
sr.Close();
res.Close();
给附加分吧!!!!!
HttpWebRequest req =(HttpWebRequest)WebRequest.Create(url);
//这里的s 是啥个东西??搞不懂
string s = "要提交的数据";
//将LoginInfo转换为byte[]格式,这里的LoginInfo应该是你要传输的数据
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(LoginInfo);
//设置请求为POST方式,
req.Method = "POST";
//设置请求类型
req.ContentType = "application/x-www-form-urlencoded";
//请求发送的数据长度, 这里就很清楚了,请求数据是从LoginInfo转换来的
//前面的代码byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(LoginInfo);
req.ContentLength = requestBytes.Length;
//建立请求的输入流
Stream requestStream = req.GetRequestStream();
//从requestBytes中读取数据到输入流中
requestStream.Write(requestBytes, 0, requestBytes.Length);
//关闭输入流
requestStream.Close();
//获取响应对象
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//获取服务器返回流
StreamReader sr = new StreamReader(res.GetResponseStream(),System.Text.Encoding.Default);
//读取返回流数据,并赋值给backstr
string backstr =sr.ReadToEnd();
//页面输出line???? 应该是backstr 吧
Response.Write(line);
//关闭* 2, 不解释了
sr.Close();
res.Close();
给附加分吧!!!!!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询