读书人

紧急求救还没睡的朋友帮忙看看,该如

发布时间: 2012-02-01 16:58:19 作者: rapoo

紧急求救,还没睡的朋友帮忙看看
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "TextBox1=test ";
// postData += ( "&Button2=Cookie ");

byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create( "http://localhost:1708/test/slogin.aspx ");

myRequest.Method = "POST ";
myRequest.ContentType = "application/x-www-form-urlencoded ";
myRequest.ContentLength = data.Length;
myRequest.AllowAutoRedirect = true;
Stream newStream = myRequest.GetRequestStream();


// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();

// Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
Response.Write(content);


-------------为什么TextBox1=test这个值无法post到目标地址:
http://localhost:1708/test/slogin.aspx

[解决办法]
没什么错误,
-------------为什么TextBox1=test这个值无法post到目标地址:
http://localhost:1708/test/slogin.aspx
估计是你取的时候有问题
还有注意编码问题

读书人网 >asp.net

热点推荐