asp.net post数据
stringurl="网址";HttpWebRequestreq=(HttpWebRequest)WebRequest.Create(url);strings="要提交的...
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是什么意思为什么前面没定义的
s没有使用过
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
在这句话中显示链接关闭。
要怎么办 展开
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是什么意思为什么前面没定义的
s没有使用过
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
在这句话中显示链接关闭。
要怎么办 展开
1个回答
展开全部
这是我以前用的方法,和你的类似,你参考一下吧。看能不能帮到你。
private static void PostData()
{
ASCIIEncoding code = new ASCIIEncoding();
string postData = "aa=iceapple.net&bb=yibin.net"; //这是要post的数据
byte[] data = code.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:7662/www/Default.aspx");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded"; //这里的ContentType很重要!
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream()) //获取数据流,该流是可写入的
{
stream.Write(data, 0, data.Length); //发送数据流
stream.Close();
}
}
private static void PostData()
{
ASCIIEncoding code = new ASCIIEncoding();
string postData = "aa=iceapple.net&bb=yibin.net"; //这是要post的数据
byte[] data = code.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:7662/www/Default.aspx");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded"; //这里的ContentType很重要!
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream()) //获取数据流,该流是可写入的
{
stream.Write(data, 0, data.Length); //发送数据流
stream.Close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询