(500) 内部服务器错误
string url = "http://localhost/t/login.aspx";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.Timeout = 100000;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
Stream newStream = httpWebRequest.GetRequestStream ();
string postData = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<s>\n"
+ "<t>\n"
+ "<user>" + txtID.Text + "</user>\n"
+ "<pass>" + txtPasswd.Text + "</pass>\n"
+ "</t>\n"
+ "</s>";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] inBuf = encoding.GetBytes(postData);
newStream.Write(inBuf, 0, inBuf.Length);
newStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.ContentLength>0)
{
Stream receiveStream = httpWebResponse.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
//通过readStream可以获得返回数据
string getData = readStream.ReadToEnd();
Response.Write(getData);
int p = getData.IndexOf ("<se>");
string se = "";
if (p > 0)
{
se = getData.Substring(p, getData.IndexOf("</se>") - p);
}
}
httpWebResponse.Close();
报错:
异常详细信息: System.Net.WebException: 远程服务器返回错误: (500) 内部服务器错误。
源错误:
行 73: newStream.Close();
行 74:
行 75: HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
行 76:
行 77: if (httpWebResponse.ContentLength>0)